Search code examples
iphonexml-parsingxmlnodedomparser

how to parse one integer node


I am new to the iPhone development and I need to parse one integer node from an xml file like this:

 <numbers>
    <current_number>1</current_number>
 </numbers>

How can I retrieve "1" as an integer through my code?

thanks, and best regards

PS: I've already implemented NSXMLParserDelegate


Solution

  • Check out a DOM parser for iPhone like GDataXMLNode. It's simpler to deal with and it has an easier API.

    If you really want to use NSXMLParser you'll need to keep track of the node you're on in the didStartElement and didEndElement methods. Then you'll use the foundCharacters method to get the value in between your node. You can then just use NSString and ask for the intValue.