DOM4J format Escape character problem

Source: Internet
Author: User
Tags cdata xml cdata

1. XML CDATA Parts that have to be said

All text in an XML document will be parsed by the parser.

Only text within a CDATA part is ignored by the parser.

An illegal XML character must be replaced with the corresponding entity.

If you use a character similar to "<" in an XML document, the parser will get an error because the parser will think that this is the beginning of a new element.

&lt; < Less than sign
&gt; > Greater-than sign
&amp; & And
&apos; ' Single quotation mark
&quot; " Double quotes

The entity must begin with the symbol "&" with the symbol ";" End.
Note: Only the "<" and "&" characters are strictly prohibited for XML. The rest is legal, and in order to reduce errors, using entities is a good habit.

CDATA Parts
All content within CDATA is ignored by the parser.

If the text contains a lot of "<" characters and "&" characters-just like the program code, it's best to put them all in a CDATA part.

A CDATA part with "<! The [cdata["Mark begins with the"]]> "tag, ending with:

CDATA Considerations:
CDATA Parts can no longer contain CDATA parts (cannot be nested). If the CDATA part contains the character "]]>" or "<! [cdata[], there will be very likely to go wrong oh.

Also note that there are no spaces or line breaks between the string "]]>".

2, dom4j format escape character problem

Person.xml

<?xml version="1.0" encoding="UTF-8"?>
<person>
         <name>张三</name>
         <addr><![CDATA[经三路<鑫苑>19F]]></addr>
</person>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.