Today's code parsing an XML times error, after checking to find that there are nested CDATA flags, resulting in changes in the XML structure, can not be converted to XML objects, Baidu, to find the following solution, the test under the to share.
Http://hi.baidu.com/yin_xiaogang/blog/item/f0f4a4ce3ef0c50592457e78.html
All content within CDATA is ignored by the parser. A CDATA part with "<! The [cdata[] mark begins with the "]]>" tag and ends. But keep in mind that CDATA cannot be nested. But now, there is someone who wants to implement CDATA nesting.
For example, add the following XML to an element in another XML:
<?xml version= "1.0" encoding= "UTF-8"?>
<System><id>library</id>
<name>library management</name>
<description><! [Cdata[this is a sample library management subsystem for Signet.]] ></description>
<Categories>
<System/>
Escapes the end of the inner CDATA. Then it becomes "<!. "Cdata[" and "]]>amp;", this is not good, the teacher said, the recipient of the XML how to know that you added an escape inside.
So, you can break the CDATA end of "]]>", divide it into two cdata, and then call the Java API to read the element's data, and the API actually reads two CDATA blocks and then synthesizes one.
Then, treat the above XML as a string and replace "]]>" with "]]]]><! [Cdata[, please remember, do not include spaces. In this way, the result should be
<?xml version= "1.0" encoding= "UTF-8"?>
<Messages>
<message type= "Data" >
<code>1199242678515-176590595</code>
<date>2008/01/02</date>
<time>10:57:58</time>
<content><! [Cdata[<?xml version= "1.0" encoding= "UTF-8"?>
<System><id>library</id>
<name>library management</name>
<description><! [Cdata[this is a sample library management subsystem for Signet.]]] ><! [cdata[></description>
<Categories>
<System/>]]></content>
</Message>
</Messages>
Thus, the data obtained using the object Org.dom4j.Element.getData () method is the original XML fragment.