nsdata 到 nsstring 到 nsdata
我正在调用网络服务。 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">
<?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 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 数据时,解析器只返回标签。然后它就卡在那里了。
I am calling the web services. The web service returns data in xml format. Now the problem is the xml data is not being received in proper format. In place of "<", ">" it returns in html form.
So I assigned the xmldata to a NsMutableString and replaced the escape characters so that the format of xml data is proper. Then I reassigned the NSMutableString to NSData so that I can parse the tags. but the problem is the xmlparser stops right where the xml data is, where I replaced the tags. It doesn't go further. What is going on?
This is the xml response from web service that I called.
<?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>
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. And then it is stuck there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你用什么解析器?在 iPhone 上,您可以使用不同的解析器(例如:TouchXML 或 TinyXML),尝试使用它们...
另外我认为你会删除
或将其替换为其他标签。然后在需要的时候进行逆变换。
What parser do you use? On the iPhone you can use different parsers (eg: TouchXML or TinyXML), try to use they...
Also I think you would remove
<?xml version="1.0" encoding="utf-8"?>
from 'return' tag or replace it with another tag. Then when needed make the inverse transformation.