You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Jose Correia <jo...@exinet.co.za> on 2000/08/08 16:50:32 UTC

questin regarding encoding value

How does Xerces pick up the encoding from an xml document? I'm trying to
obtain the encoding's code so that I can pass it through to an xsl
file... and I can't seem to find a method in the xerces API to do that.

Thanks in advance
Jose Correia
Exinet (Pty) Ltd




--

                \=/,         _-===-_-===-_-===-_-===-_-==-_
                |  @___oo  (                               )_
      /\  /\   / (___,,,}_--=                                )
     ) /^\) ^\/ _)        =_"Positive thinking - a great way  )
     )   /^\/   _)         (_        to face life"             )
     )   _ /  / _)          (        Jose Correia            )
 /\  )/\/ ||  | )_)          (_    jose@exinet.co.za        )
<  >      |(,,) )__)           (   jcorreia@global.co.za    )
 ||      /    \)___)\           (_                        _)
 | \____(      )___) )___          -==-_______-=====-___==
  \______(_______;;; __;;;



Re: questin regarding encoding value

Posted by Andy Clark <an...@apache.org>.
Jose Correia wrote:
> How does Xerces pick up the encoding from an xml document? I'm 
> trying to obtain the encoding's code so that I can pass it through 
> to an xsl file... and I can't seem to find a method in the xerces 
> API to do that.

You are able to pick up the encoding information from the internal
callbacks that the scanner makes. If you look at the XMLDocument-
Handler interface, there is a method for the xmlDecl and textDecls
that appear in the document entity and other general entities.

By extending either the SAXParser or DOMParser, you can override
these methods (both parsers implement the XMLDocumentHandler
interface) and retrieve the encoding information. You'll have to
query the string from the string pool, though. Here's how you do
that:

  public class MyDOMParser extends DOMParser {
    public void xmlDecl(int versionIndex, 
                        int encodingIndex, 
                        int standaloneIndex) throws Exception {
      String encoding = fStringPool.toString(encodingIndex);
      super.xmlDecl(versionIndex, encodingIndex, standaloneIndex);
    }
  }

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org