我如何解析这样的xml,有一个节点和不同的参数在它使用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="example@abcd.org" 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>
这里供应商有不同的参数,所以如何使用nsxmlparser解析它?
当使用NSXMLParser时,你的委托将实现方法parser:didStartElement:namespaceURI:qualifiedName:attributes:
。当以"vendor"元素名调用时,attributes
将是带"parameters"的NSDictionary
。在字典中查找缺失的参数将返回nil
。
官方文档有一个包含大量示例代码的XML编程指南,包括如何处理元素和属性。