如何获取SOAP响应数据?

时间:2012-08-14 10:32:47

标签: objective-c xml serialization soap

这是来自webservice的XML回复。

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:OrientalServices1">
<SOAP-ENV:Body>
<ns1:Get_CategoryResponse xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:responseGetCategoryByID[11]">
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">1</id>
    <name xsi:type="xsd:string">國內</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">2</id>
    <name xsi:type="xsd:string">財經</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">3</id>
    <name xsi:type="xsd:string">社會</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">4</id>
    <name xsi:type="xsd:string">國際</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">10</id>
    <name xsi:type="xsd:string">龍門陣</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">11</id>
    <name xsi:type="xsd:string">言論</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">6</id>
    <name xsi:type="xsd:string">名家</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">8</id>
    <name xsi:type="xsd:string">娛樂</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">5</id>
    <name xsi:type="xsd:string">體育</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">7</id>
    <name xsi:type="xsd:string">專題</name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">9</id>
    <name xsi:type="xsd:string">特輯</name>
</item>
</return>
</ns1:Get_CategoryResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

在这个XML中,我在一个数组中有11个项目。如何反序列化并逐个获取项目?

1 个答案:

答案 0 :(得分:0)

您可以使用XML解析器。

在Cocoa中支持几种方法 - 但是既然你已经提出了这样一个普遍的问题,我所能做的就是提供一般性答案。

Apple开发人员网站上有Introduction to Event Driven XML Programming