NSXMLParser 空节点引起的过早文档结束错误?

发布于 2024-09-16 11:44:19 字数 640 浏览 21 评论 0原文

我正在使用 NSXMLParser 来解析从远程托管的 Web 服务返回的 XML 文档。 XML 是有效的,但某些节点偶尔会为空,这似乎会导致 NSXMLParser 崩溃(NSXMLParserErrorDomain 错误 5),但是我在网上找不到任何内容,这表明解析空节点会出现问题,因此我想知道是否还有其他人遇到过这方面的任何问题,并且可以证实或否认我的理论,即 NSXMLParser 无法处理空标签?

我的 XML 大致如下:

<前><代码><条目> <请求>2123456789<名称> <用户名>用户名 <密码>密码 <会话ID>987654321 <最旧的> <最新> <列表>

解析器在到达元素时会抛出一个错误,它调用 DidStartElement,然后消失在解析器代码中,并在调用任何更多委托方法之前抛出一个错误。

I'm using NSXMLParser to parse an XML document which is being returned from a web service hosted remotely. The XML is valid but some of the nodes will occasionally be empty, this seems to cause NSXMLParser to fall over (NSXMLParserErrorDomain error 5) however I can't find anything on the net which would suggest that there would be an issue parsing empty nodes so I wondered if anyone else had experienced any problems with this and could confirm or deny my theory that NSXMLParser can't cope with empty tags?

My XML goes something along the lines of:

<Entry>  
    <Request>2</Request>  
    <ID>123456789</ID>  
    <Name></Name>  
    <UserName>username</UserName>  
    <Password>password</Password>  
    <SessionID>987654321</SessionID>  
    <Oldest></Oldest>  
    <Newest></Newest>  
    <List></List>  
</Entry>

The parser throws an error when it gets to the element, it calls DidStartElement and then disappears off into the parser code and throws an error back before it calls any more delegate methods.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-09-23 11:44:19

您的问题很可能来自 NSXMLParser 的实现。我的 NSXMLParser 实现可以很好地处理空节点,尽管我还没有找到一种方法来实际将 @"" 存储在我从 XML 生成的字典中的空节点内。当 NSXMLParser 遇到空节点时,永远不会调用 parser:foundCharacters: ,因此您在那里或在 parser:didEndElement: 中的实现几乎肯定会导致问题。

Your problem most likely comes from your implementation of NSXMLParser. My implementation of NSXMLParser handles empty nodes just fine, though I haven't figured out a way to actually store @"" inside of empty nodes in the dictionary that I'm producing from the XML. parser:foundCharacters: is never called when NSXMLParser hits an empty node, so your implementation there or in parser:didEndElement: is almost certainly causing the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文