[英]How to parse the xml data using NSXML Parser in iPhone?
I want to parse the XML data using NSXMLParser. 我想使用NSXMLParser解析XML数据。 In my root node is location and i want to extract the values for street, city, state and postal_code. 在我的根节点中是位置,我想提取街道,城市,州和邮政编码的值。 I could take the name attribute values and how can i take the inner values of address node. 我可以采用名称属性值,以及如何采用地址节点的内部值。
Here the xml node is, 这是xml节点,
<location id="10001">
<name>Pugal Devan</name>
<address>
<street>112, Jawahar Street </street>
<city>Kolkata</city>
<state>West Bengal</state>
<postal_code>10002</postal_code>
</address>
</location>
Thanks! 谢谢!
You could create a class that looks like: 您可以创建一个类似于以下内容的类:
@interface Location {
NSString* name;
NSString* street;
NSString* city;
NSString* state;
NSString* postalCode;
}
Then just use the normal methods to parse the XML while creating Location
objects to hold the parsed data. 然后,在创建Location
对象以保存解析的数据时,只需使用常规方法即可解析XML。 Here is a very thorough example on how to parse the data. 这是有关如何解析数据的非常详尽的示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.