我如何解析这样一个包含一个标签和不同参数的 xml?
我如何使用 NSXMLParser 解析这样的 xml,其中有一个节点和不同的参数?
<vendorlist>
<statusdescription>success</statusdescription>
<statuscode>200</statuscode>
<statistic vendor_count="1" page="1" page_count="1"/>
<vendor id="1581" name="Islan Name is here" street="The address is here" state="USVI" zip="802" phone1="340-774-3944" phone2="" email="[email protected]" website1="" website2="" longitude="" latitude="" description="this is very important discription here, for this vendor" picture_img="http://igy.match3win.com/img/picture/NULL" logo_img="http://igy.match3win.com/img/logo/1581.jpg"/>
</vendorlist>
这里Vendor里面有不同的参数,那么如何使用nsxmlparser解析它呢?
How can I parse such xml, having one node and different arguments in it using NSXMLParser?
<vendorlist>
<statusdescription>success</statusdescription>
<statuscode>200</statuscode>
<statistic vendor_count="1" page="1" page_count="1"/>
<vendor id="1581" name="Islan Name is here" street="The address is here" state="USVI" zip="802" phone1="340-774-3944" phone2="" email="[email protected]" website1="" website2="" longitude="" latitude="" description="this is very important discription here, for this vendor" picture_img="http://igy.match3win.com/img/picture/NULL" logo_img="http://igy.match3win.com/img/logo/1581.jpg"/>
</vendorlist>
Here Vendor has different parameters in it, so how can parse it using nsxmlparser?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 NSXMLParser 时,您的委托将实现方法
解析器:didStartElement:namespaceURI:qualifiedName:attributes:
。当使用元素名称“vendor”调用它时,attributes
将是一个带有“parameters”的NSDictionary
。在字典中查找缺失的参数将返回nil。官方文档有一个 XML 编程指南有很多示例代码,包括如何处理元素和属性。
When using NSXMLParser, your delegate will implement the method
parser:didStartElement:namespaceURI:qualifiedName:attributes:
. When it's called with element name of "vendor",attributes
will be aNSDictionary
with the "parameters". Looking for missing parameters in the dictionary will returnnil
.The official documentation has a XML Programming Guide with lots of example code, including on how to handle elements and attributes.