Sriram Rao wrote:
> I was interested in getting the encoding information in the prolog of an
> incoming XML document (from an external source) so that I can set the
> encoding when I write back the XML in printable form.

That information is not exposed via the DOM. You would have
to subclass the DOMParser (or SAXParser) to get that info in
the xmlDecl method of the internal interfaces (which the 
parser class implements).

In Xerces 1.x, you'll have to use the StringPool but that's
not very hard. For example:

  public void xmlDecl(int versionIndex, int encodingIndex,
                      int standaloneIndex) throws Exception {
    super.xmlDecl(versionIndex, encodingIndex, standaloneIndex);

    String encoding = fStringPool.toString(encodingIndex);
  }

In Xerces2, you actually have two choices: 1) the method
startDocument gives you the name of the auto-detected
encoding, and 2) the method xmlDecl gives you the encoding
specified in the XMLDecl at the beginning of the document.
In the new version, you don't have to use a StringPool 
because the String objects are passed directly.

-- 
Andy Clark * IBM, TRL - Japan * [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to