English 中文(简体)
• 避免XML特征的最佳做法?
原标题:Best practise to escape XML characters?

I ve got html datas that i m converting into a Dom4J document.

我发现了一个错误:

org.dom4j.DocumentException: Error on line 1 of document  : Reference is not allowed in prolog. Nested exception: Reference is not allowed in prolog.
    at org.dom4j.io.SAXReader.read(SAXReader.java:482)
    at org.dom4j.DocumentHelper.parseText(DocumentHelper.java:278)
    at MonTest.main(MonTest.java:21)
Nested exception: 
    org.xml.sax.SAXParseException: Reference is not allowed in prolog.

它是“和;”的特性,即为了建立该文件,需要逃入和安放。

在XML中,我们似乎需要逃脱5个特征:(大体、带、引、安插、apos)

然而,在不将其纳入“目标”要素的情况下,如何逃脱:

<div id="test" class= toto >A&A<A"A</div>

应当:

<div id="test" class= toto >A&amp;A&lt;A&quot;A</div>

而不是

&lt;div id=&quot;test&quot; class=&apos;toto&apos;&gt;A&amp;A&lt;A&quot;A&lt;/div&gt;

Thank you,

最佳回答

Escape strings before adding to XML document. Use StringEscapeUtils.escapeXml method from Apache Commons Lang. Use some library to build XML e.g. http://code.google.com/p/joox/.

问题回答

我将仔细研究使用超文本超文本XMLReader,而不是缺省XMLReader执行。 诸如的标签,即html tidy





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签