简体   繁体   中英

How to parse element tags present in the CDATA section of any tag in XML using java

I am currently trying to parse xml file using java but while parsing i am unable to parse the tags present inside the CDATA section of any element tag. The whole data inside the CDATA section is being parsed as text while parsing using DOM or SAX.

please suggest any way without any hard coding.

<Evaluation>
<![CDATA[<evaluation>
<interview ratingtype="0"/>
<item description="Ability to communicate well with others verbally and in writing:" hasrating="True" hascomments="False" /> ............ </item>
 </evaluation> ]]
</Evaluation>

CDATA sections are text nodes. So the parser is correct reading it as a single string. CDATA sections mean that the parser will not do any decoding of entities. You can read more about it in the specification .

If you want to treat the contents of a CDATA section as an XML document or fragment you need to do this manually - in other words: parse it separately.

CDATA represents text nodes, as mentioned above. It won't make sense to keep tags inside a CDATA section. CDATA should be used to store plain strings.

In this case the , and tags won't get parsed as elements by the parser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM