Hi Rob,

If you're using the latest version of the parser (Xerces 2.4.0), you
should be able to retrieve the encoding using SAX. Have a look at:
http://xml.apache.org/xerces2-j/faq-general.html#faq-8. The solution isn't
particularly elegant, but SAX's Locator2 interface isn't available yet.

Just to clarify some things for you:

<?xml ... ?> is an xml declaration. It isn't a processing instruction, so
it won't be reported to your ContentHandler.

SAX is read only, so if you need to change the encoding of your instance
document, you'd have an easier time using DOM. i.e. Parsing your document
(in whatever encoding) into a DOM, and then serializing it back with UTF-8
as the output encoding.

Hope that helps.

On Wed, 18 Jun 2003, Rob Outar wrote:

> I have to write a program that will fetch the encoding information from XML
> files:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> and verify that all encoding is set to UTF-8, my early trials using SAX has
> not worked, I thought it was a preprocessing instruction but I did not get
> the callback for my test files.  Is there an easy way to fetch and possibly
> update the encoding value?
>
> Thanks,
>
> Rob
>

--------------------
Michael Glavassevich
[EMAIL PROTECTED]

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

Reply via email to