nsxmlparser 无法解决 '
我使用 NSXMLParser 来剖析 xml 包,我在包文本中接收到 &apos 。
我为 xmlParser 定义了以下内容:
[xmlParser setShouldResolveExternalEntities: YES];
永远不会调用以下方法
- (void)parser:(NSXMLParser *)parser foundExternalEntityDeclarationWithName:(NSString *)entityName publicID:(NSString *)publicID systemID:(NSString *)systemID
解析器不考虑 &apos 之前字段中的文本。
我正在寻找如何解决这个问题,有什么想法吗???
提前致谢 附上Alex
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/" xmlns:tns="urn:appwsdl"><SOAP-ENV:Body><ns1:getObjects2Response xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="tns:objectsResult"><totalRecipes xsi:type="xsd:string">1574</totalObjects><Objects xsi:type="tns:Item"><id xsi:type="xsd:string">4311</id><name xsi:type="xsd:string"> item title 1 </name><procedure xsi:type="xsd:string">item procedure 11......
Im using NSXMLParser to dissect a xml package, I'm receiving &apos inside the package text.
I have the following defined for the xmlParser:
[xmlParser setShouldResolveExternalEntities: YES];
The following method is never called
- (void)parser:(NSXMLParser *)parser foundExternalEntityDeclarationWithName:(NSString *)entityName publicID:(NSString *)publicID systemID:(NSString *)systemID
The text in the field before the &apos is not considered by the parser.
Im searching how to solve this, any idea???
Thanks in advance
Alex
XML package portion attached:
<?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/" xmlns:tns="urn:appwsdl"><SOAP-ENV:Body><ns1:getObjects2Response xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/"><return xsi:type="tns:objectsResult"><totalRecipes xsi:type="xsd:string">1574</totalObjects><Objects xsi:type="tns:Item"><id xsi:type="xsd:string">4311</id><name xsi:type="xsd:string"> item title 1 </name><procedure xsi:type="xsd:string">item procedure 11......
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我在参考这里的不同答案后所做的。
当从 NSURLConnection 对象接收数据时,我用
"'"
替换了 xml 中所有出现的'
。然后我将该数据提供给解析器。所以我要做的是:
这是resolveHTMLEntitites 方法:
问题是
'
被转换为'
这就是为什么我们需要替换它发生。注意:上面的代码块中没有执行内存管理。
希望这有帮助。
Here is what I did, after referring a different answer from here.
I replaced all the occurrences of the
'
in the xml with"'"
when the data is received from NSURLConnection object. Then I give that data to the parser.So what I do is:
Here is the resolveHTMLEntitites method:
The catch is that
'
gets converted to'
thats why we need to replace that occurrence.Note: No memory management is performed in the above block of code.
Hope this helps.
标准实体为
<
、>
、&
和".
'
是 html 实体引用。您的 XML 是否引用了 XHTML 命名空间或定义了'
的其他命名空间?(顺便说一句,如果能看到一小段 XML 包括标头,那就太好了。)
The standard entities are
<
,>
,&
, and"
.'
is an html entity reference. Does your XML refer to the XHTML namespace or some other namespace that has'
defined?(BTW, would be nice to see a small segment of the XML including the header.)