XML 中的 CDATA 块解析应如何表现?
给定这个 XML 片段:
<title><![CDATA[Resizing & Cropping GIF and PNG images issue]]></title>
XML 解析器应该为
1. "Resizing & Cropping GIF and PNG images issue"
2. "Resizing & Cropping GIF and PNG images issue"
注意:我使用的是 Java 的 ROME 提要解析库,它将其解析为#2,但根据我对 CDATA 块的理解,它应该是#1。我在网上找到的证据表明 #2 都是 正确(也此处 )和错误 - 所以我对此有点困惑(并且好奇)。
Given this XML snippet:
<title><![CDATA[Resizing & Cropping GIF and PNG images issue]]></title>
What is the correct string that should be parsed by the XML parser for the <title> element content?
1. "Resizing & Cropping GIF and PNG images issue"
2. "Resizing & Cropping GIF and PNG images issue"
Note: I'm using the ROME feed parsing library for Java, which parses this as #2, but from my understanding of CDATA blocks it should be #1. I've found evidence on the web that suggests #2 is both right (also here) and wrong - so I'm a bit perplexed (and curious) about this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,与您认为“错误”的第二个链接有很大不同。您将其用于标题而不是链接/网址。我会使用第二个,因为它是有效的 XML。我知道 CDATA 会忽略它,但我不确定你为什么要忽略标题。
你打算用这个做什么?在我看来,您不想对所有内容进行 CDATA,因为有效 XML 的优点在于您知道它应该与 XML 解析器显示一致。
Well from what I can tell there is a big difference from the 2nd link where you think it's "wrong". You are using it for titles and not links/urls. I would use the 2nd one as that is valid XML. I understand that CDATA will then ignore it, but I'm not sure why you would want to ignore the title.
What are you planning on using this for? It seems to me that you would want to not CDATA everything, as the beauty in valid XML is that you know it should display consistent with XML parsers.