XML file with ä
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);
链接地址: http://www.djcxy.com/p/85690.html
上一篇: jsp标签中的动态属性
下一篇: 带有&auml的XML文件;