简体   繁体   中英

Java: Error while parsing XML document as text

I'm trying to parse XML document as String by using the following

Document parse = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new StringReader(xmlFile)));

but I'm getting this error

[Fatal Error] The entity "Ouml" was referenced, but not declared.

I tried escape and unescape xmlFile String using Apache StringEscapeUtils but still having errors

HTML 4.0 knows 252 predefined character-entities like Ö , ß etc.

XML on the other hand only has 5:

"
&
'
<
>

You can't use named character-entities from html other than those without defining them first.

So when using StringEscapeUtils make sure you use escapeXml() instead of escapeHtml4() .

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