开发者

How to parse nested xml in iPhone?

<Row>
<row>1</row>
<priority>Low</priority>
<message>
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="1">HIII</FONT></P></TEXTFORMAT>
</message>
<subject></subject>
<status><B><font color='#FF0000'>Mark Read </font></B></status>
<flagstatus>1</flagstatus>
<message_id>78</m开发者_JS百科essage_id>
</Row>

Message for "Marry" data:

<message>
<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="12" COLOR="#000000" LETTERSPACING="0" KERNING="1">Marry</FONT></P></TEXTFORMAT>
</message>

How to parse this kind of xml format and fetch "Marry" data in the above example.

Any reply is appreciated. Thanks.


You can use NSScanner, it works both on the iphone and mac. It is a class that basically wraps NSString to be able to scan the string.

You initialize the NSString with your XML source and then you create an NSSCanner object with that string to scan the string in a while loop. ( while( ![scanner isAtEnd] ) )

NSScanner class reference and how to use


To parse xml in iOS, you can also use NSXMLParser.
The Event-Driven XML Programming Guide has details and examples.


http://ioslazyworks.blogspot.in/2013/05/ios-universal-xml-parser.html

This tutorial helps in parsing XML without giving tags in inputs. Its a static library which handles the parsing logic and responds in delegates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜