Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ilx.mac

macrumors member
Original poster
Mar 10, 2009
63
0
Hi Friends,

I am building an iphone application. I need to build an xml from NSString Data. I am new to this iphone development. Can some one help me by sending / posting some sample codes to build an xml using NSString.

Thanks in Advance!
 
Hi Friends,

I am building an iphone application. I need to build an xml from NSString Data. I am new to this iphone development. Can some one help me by sending / posting some sample codes to build an xml using NSString.

Thanks in Advance!

Not quite sure how to answer this; XML is (within the limits of it being a structured document) fairly free-form, since you get to define the tags, element properties, etc. For instance,

Code:
[NSString stringWithFormat:@"<bacon>%@</bacon>", aString];

is a perfectly valid way to construct XML from an NSString. Maybe you'd benefit from reading up a little on XML: http://en.wikipedia.org/wiki/XML and NSStrings: http://developer.apple.com/document...lasses/NSString_Class/Reference/NSString.html.
 
Re

Thanks for your prompt reply Jnic. I am getting a reply from web server as a NSString (*thereply). and the data from string thereply reads - <root><type>text</type></root>. Now will it be possible for me to get the values from the node as we do it in Java/.Net.

Thanks in Advance!
 
Re

Thanks Jnic. I think i can explain my problem in brief.

#1. I have a webserver.
#2. I have a client, which sends request to the webserver.
#3. The webserver responds me with <root><name>Todd</name><age>25</age></root>.
#4. The returned value is not an xml, its an string.
#5. I have to build the string to an xml. (In c#, we would load the string to an xmldom object to convert to an xml). Here i am unable to do this.
#6. After building an xml I have to parse it & retrive the node values.

Can you help me on this? its very urgent for me.

Thanks in Advance!
 
#1. I have a webserver.
#2. I have a client, which sends request to the webserver.
#3. The webserver responds me with <root><name>Todd</name><age>25</age></root>.
#4. The returned value is not an xml, its an string.
#5. I have to build the string to an xml. (In c#, we would load the string to an xmldom object to convert to an xml). Here i am unable to do this.
#6. After building an xml I have to parse it & retrive the node values.
#2. I'm assuming your client is an iPhone or you wouldn't be in this forum.
#4. "An XML". "A string". This is just a matter of perspective. And doesn't really matter. Your returned value is an XML document of some form.

SO, as jnic said, you'll need to figure out how to use NSXMLParser to parse through the XML document that your request returns. A good place to see some sample code to learn about this is the SeismicXML sample app.
 
Re

thanks Dejo,

I went through the code, but i cant find code to build a xml from string. Can you send me some code samples please!
 
I went through the code, but i cant find code to build a xml from string.
If you're using NSXMLParser, you're not going to get a string as a response. In fact, it uses an event-driven approach where you need to provide code to handle things inside the didStartElement and didEndElement methods. And I believe NSXMLParser is the only XML-handling that's part of the API. So, if you aren't using this, you'll have to "roll your own", as they say.
 
simple window with sample

see attached zip file
it's a window, with a text box, a label, and a button.
input <xml><into>text box</into></xml>
press the button.

so it's xcode 5.1
simple cocoa application, but should suffice in an ios app as well.
 

Attachments

  • ParseXMLString.zip
    34.7 KB · Views: 170
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.