从nsdata到nsstring到nsdata

问题描述 投票:0回答:1

我正在呼叫Web服务。 Web服务以xml格式返回数据。现在的问题是未以正确的格式接收xml数据。代替“ ”以html形式返回。

因此,我将xmldata分配给NsMutableString并替换了转义字符,以便xml数据的格式正确。然后,我将NSMutableString重新分配给NSData,以便我可以解析标签。但是问题是xmlparser停在xml数据所在的位置,我替换了标签。它不会进一步。这是怎么回事?

这是我调用的来自Web服务的xml响应。

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope 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/">
<SOAP-ENV:Body>
<ns1:GetCustomerInfoResponse xmlns:ns1="http://aa.somewebservice.com/phpwebservice">
<return xsi:type="xsd:string">
    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;customer&gt;&lt;id&gt;1&lt;/id&gt;&lt;customername&gt;Hitesh&lt;/customername&gt;&lt;phonenumber&gt;98989898&lt;/phonenumber&gt;&lt;/customer&gt;
</return>
</ns1:GetCustomerInfoResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

这是在我替换标签之后。

<?xml version="1.0" encoding="ISO-8859-1"?><SOAP-ENV:Envelope 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/">
<SOAP-ENV:Body>
<ns1:GetCustomerInfoResponse xmlns:ns1="http://aa.somewebservice.com/phpwebservice">
<return xsi:type="xsd:string">
<?xml version="1.0" encoding="utf-8"?> 
 <customer><id>1</id><customername>Hitesh</customername><phonenumber>98989898</phonenumber></customer>
</return>
</ns1:GetCustomerInfoResponse>
</SOAP-ENV:Body></SOAP-ENV:Envelope>

现在问题是在解析xml数据时,解析器只会返回标签。然后它被卡在那里。

iphone nsdata web-services nsmutablestring xml-parsing
1个回答
1
投票

您使用什么解析器?在iPhone上,您可以使用不同的解析器(例如:TouchXMLTinyXML),请尝试使用它们...

[另外,我想您会从'return'标签中删除<?xml version="1.0" encoding="utf-8"?>或将其替换为另一个标签。然后在需要时进行逆变换。

© www.soinside.com 2019 - 2024. All rights reserved.