Java – XML file with & auml;
                                        
                    •
                    Java                                    
                I have an XML file roughly as follows:
<customer>
    <name>Müller</name>
</customer>
I use the following code to parse the file:
File xmlFile = new File("file.xml");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(xmlFile)
And get the error of the entity uuml; Referenced but undeclared What I want is to read the entry but not parse it in any way. I want to get the value written in the file
What do I do?
Solution
I tried setting:
dbFactory.setExpandEntityReferences(false);
But it doesn't work
If you can't modify your XML content (using UTF-8, XML can contain your umlaut), you can add a DTD:
<!DOCTYPE deFinition [ <!ENTITY uuml "ü"> ]>
If you cannot modify the XML file, load the XML content and add 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);
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        