开发者

How should CDATA block parsing in XML behave?

开发者 https://www.devze.com 2023-02-13 04:29 出处:网络
Given this XML snippet: <title><![CDATA[Resizing & Cropping GIF and PNG images issue]]></title>

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 &amp; 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 eviden开发者_运维问答ce on the web that suggests #2 is both right (also here) and wrong - so I'm a bit perplexed (and curious) about this.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号