Hi,

I want to determine the encoding ("iso-8859-1" on the example below) of
a existing/read XML file.

Have only found "getEncoding()" method for org.xml.sax.InputSource (and
OutputFormat) - tried it, didn't worked!  Then I tried to get it via a
org.dom4j.ProcessingInstruction named "xml" - didn't worked.

Any ideas how to get it?  Or is this a bug in the implementation(s)?
Used latest dom4j 1.3, jdk 1.3.

Thanx,
Peter

--- CUT HERE ---

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd";>

<article lang="en">
<!-- some content -->
</article>

--- CUT HERE ---

public void transform (File inFile) throws Exception {
        String encoding = "I want to get the encoding of the XML file!";
        InputSource is = new InputSource(new FileInputStream(inFile));
        if (is.getEncoding() != null) {
                encoding = is.getEncoding();
        } else {
                System.out.println("No encoding detected via
InputSource!");
        }

        Document doc = sr.read(inFile);
        ProcessingInstruction pi = doc.processingInstruction("xml");
        if (pi != null) {
                encoding = pi.getValue("encoding");
        } else {
                System.out.println("No encoding detected via Processing
Instruction!");
        }
        // ... more instructions ...
}

--- CUT HERE ---






_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to