XML file with & auml;

I have an XML file that looks something like this:

<customer> <name>M&uuml;ller</name> </customer> 

I will analyze the file using the following code:

 File xmlFile = new File("file.xml"); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile) 

And get the error referenced by the &uuml; but not announced. I want the record to be read, but not processed in any way, I want to get the value because it is written to the file.

How to do it?

+7
java xml
source share
1 answer

I tried setting:

 dbFactory.setExpandEntityReferences(false); 

but it does not work.

If you cannot change the contents of xml (using UTF-8, xml may contain u umlaut), you can add DTD:

 <!DOCTYPE definition [ <!ENTITY uuml "&#xfc;"> ]> 

If you cannot change your XML file, upload the xml content and add the DTD:

 String dtd = "<!DOCTYPE definition [\n<!ENTITY uuml '&#xfc;'>\n]>\n", contents = <load xmlFile>; Reader reader = new StringReader(dtd + contents); InputSource src = new InputSource(reader); Document doc = dBuilder.parse(src); 
+4
source share

All Articles