I have a XML file that roughly looks like this:
<customer>
<name>Müller</name>
</customer>
I parse the file using 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 that the entity ü
is referenced but not declared. What I want is that the entry is being read but not parsed in any way, I want to get the value as it is written in the file.
How do I do that?
I tried setting:
dbFactory.setExpandEntityReferences(false);
but this doesn't work.
If you can't modify your xml content (using UTF-8 the xml can contain u umlaut), you might be able to add a DTD:
<!DOCTYPE definition [
<!ENTITY uuml "ü">
]>
If you can't modify your xml file, load the xml contents and prepend the DTD:
String dtd = "<!DOCTYPE definition [\n<!ENTITY uuml 'ü'>\n]>\n",
contents = <load xmlFile>;
Reader reader = new StringReader(dtd + contents);
InputSource src = new InputSource(reader);
Document doc = dBuilder.parse(src);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With