简体   繁体   English

nsdata 到 nsstring 到 nsdata

[英]nsdata to nsstring to nsdata

I am calling the web services.我正在调用网络服务。 The web service returns data in xml format. Web 服务以 xml 格式返回数据。 Now the problem is the xml data is not being received in proper format.现在的问题是没有以正确的格式接收 xml 数据。 In place of "<", ">" it returns in html form.代替“<”,“>”,它以 html 形式返回。

So I assigned the xmldata to a NsMutableString and replaced the escape characters so that the format of xml data is proper.所以我将 xmldata 分配给一个 NsMutableString 并替换了转义字符,以便 xml 数据的格式正确。 Then I reassigned the NSMutableString to NSData so that I can parse the tags.然后我将 NSMutableString 重新分配给 NSData 以便我可以解析标签。 but the problem is the xmlparser stops right where the xml data is, where I replaced the tags.但问题是 xmlparser 就在 xml 数据所在的地方停止,我在那里替换了标签。 It doesn't go further.它没有更进一步。 What is going on?到底是怎么回事?

This is the xml response from web service that I called.这是我调用的 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>

And this is after I replaced the tags.这是在我更换标签之后。

<?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>

Now the problem is while parsing the xml data, the parser only goes up to return tag.现在的问题是在解析 xml 数据时,解析器只上升到返回标记。 And then it is stuck there.然后它就卡在那里了。

What parser do you use?你用什么解析器? On the iPhone you can use different parsers (eg: TouchXML or TinyXML ), try to use they...在 iPhone 上,您可以使用不同的解析器(例如: TouchXMLTinyXML ),尝试使用它们...

Also I think you would remove <?xml version="1.0" encoding="utf-8"?> from 'return' tag or replace it with another tag.此外,我认为您会从 'return' 标签中删除<?xml version="1.0" encoding="utf-8"?>或将其替换为另一个标签。 Then when needed make the inverse transformation.然后在需要时进行逆变换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM