0

这是XML从 web 服务返回的响应。

<?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">龍門陣&lt;/name>
</item>
<item xsi:type="tns:responseGetCategoryByID">
    <id xsi:type="xsd:int">11</id>
    <name xsi:type="xsd:string">言論&lt;/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 个项目。如何反序列化并一一获取项目?

4

1 回答 1

0

您可以使用 XML 解析器。

Cocoa 中支持几种方法——但既然你问了这样一个笼统的问题,我所能做的就是提供一个笼统的答案。

Apple 开发者网站上有一篇关于事件驱动 XML 编程的介绍

于 2012-08-14T10:36:08.277 回答