【问题标题】:nsdata to nsstring to nsdatansdata 到 nsstring 到 nsdata
【发布时间】:2011-03-02 22:41:18
【问题描述】:

我正在调用网络服务。 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】:

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

    另外我认为你会从'return'标签中删除&lt;?xml version="1.0" encoding="utf-8"?&gt;或用另一个标签替换它。然后在需要的时候进行逆变换。

    【讨论】:

    • 嘿,谢谢。这就是问题所在。一旦我从响应中删除了该标签,它就起作用了。
    猜你喜欢
    • 2012-01-17
    • 2011-08-31
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多