javaxmliso-8859-1dom4jxml-encoding

DOM4J Document: read an ISO-8859-1 xml


I need to read an xml file that is encoded in ISO-8859-1.

I'm using:

Document document = reader.read(new File(sourceFile));
document.setXMLEncoding("ISO-8859-1");

I'm getting a "cannot find symbol" error for setXMLEncoding. This seems like it should be a simple thing, but I can't figure out what I'm doing wrong.


Solution

  • The setXMLEncoding is available since dom4j 1.6. I guess you're using an older version.

    Anyway, as the javadoc says:

    Sets the encoding of this document as it will appear in the XML declaration part of the document.

    you should use that method if you're writing an xml. I guess you're reading an existing file, so if it's ISO-8859-1 encoded and its prolog contains the same encoding declaration, you shouldn't have any problem, dom4j should do everything for you.

    <?xml version="1.0" encoding="ISO-8859-1"?>