I use an outside parser method to do this - I do not know any parser API that allows this : (LGPL code - out of http://xemelios.org)

    protected static String getFileEncoding(File f) throws IOException {
        String ret = "UTF-8";
        try {
            BufferedInputStream bis = new BufferedInputStream(new FileInputStream(f));
            byte[] bb = new byte[255];
            int read = bis.read(bb);
            if (read < 255) {
                logger.info("while reading " + f.getName() + " for getFileEncoding(), can only read " + read + " bytes.");
            }
            String buff = new String(bb);
            buff = buff.substring(buff.indexOf("<?"));
            buff = buff.substring(0, buff.indexOf("?>") + 2);
            String header = buff;
            int encodingPos = header.indexOf("encoding=");
            if (encodingPos >= 0) {
                String s = header.substring(encodingPos + 9);
                if (s.startsWith("\"")) {
                    ret = s.substring(1, s.indexOf('"', 1));
                } else {
                    s = s.substring(0, s.length() - 2).trim();
                    if (s.indexOf(' ') > 0) {
                        ret = s.substring(0, s.indexOf(' '));
                    } else {
                        ret = s;
                    }
                }
            } else {
                ret = "UTF-8";
            }
            bis.close();
        } catch (Exception ex) {
            logger.error("getFileEncoding(File)" + ex);
        }
        logger.debug("encoding=" + ret);
        return ret;
    }


Le 14/07/2011 15:46, Kunal Chauhan a écrit :
Hi,
 
Actually I want to build a validation rule that checks whether particular document is of UTF-8 encoding type or not ?
that's why I want to check.
 


 
On Thu, Jul 14, 2011 at 7:05 PM, Michael Kay <mike@saxonica.com> wrote:
On 14/07/2011 12:10, Kunal Chauhan wrote:
> Hello,
> I want to check encoding of XQ item which I bind?
> like encoding='UTF-8'.
>

Saxon doesn't have any information about the encoding of an XML document
- that's all taken care of by the XML parser, and most XML parser APIs
don't reveal it to the application (which shouldn't need to care).

Why do you need to know?

Michael Kay
Saxonica

------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric
Ries, the creator of the Lean Startup Methodology on "Lean Startup
Secrets Revealed." This video shows you how to validate your ideas,
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--
Kunal Chauhan
mail4ck@gmail.com
[+918655517141]
[+919904983614]

------------------------------------------------------------------------------ AppSumo Presents a FREE Video for the SourceForge Community by Eric Ries, the creator of the Lean Startup Methodology on "Lean Startup Secrets Revealed." This video shows you how to validate your ideas, optimize your ideas and identify your business strategy. http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help