如何向sax请求文件编码 [英] How to ask sax for the file encoding

查看:55
本文介绍了如何向sax请求文件编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照通常的食谱示例,我的应用程序解析一个打开的文件,因为

如下:


parser = xml.sax.make_parser()


parser.setFeature(xml.sax.handler.feature_external _ges,1)


#希望内容处理程序可以从<计算出编码;?xml>

元素。


handler = saxContentHandler(c,inputFileName,silent)


解析器。 setContentHandler(handler)


parser.parse(theFile)


任何人都可以告诉我内容处理程序如何确定
档案?萨克斯可以提供这个信息吗?


谢谢!


爱德华

--------- -------------------------------------------------- ---------

Edward K. Ream电子邮件: ed ***** **@charter.net

狮子座: http://webpages.charter.net/edreamleo/front.html

--------------------- -----------------------------------------------

Following the usual cookbook examples, my app parses an open file as
follows::

parser = xml.sax.make_parser()

parser.setFeature(xml.sax.handler.feature_external _ges,1)

# Hopefully the content handler can figure out the encoding from the <?xml>
element.

handler = saxContentHandler(c,inputFileName,silent)

parser.setContentHandler(handler)

parser.parse(theFile)

Can anyone tell me how the content handler can determine the encoding of the
file? Can sax provide this info?

Thanks!

Edward
--------------------------------------------------------------------
Edward K. Ream email: ed*******@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------

推荐答案

Edward K. Ream写道:
Edward K. Ream wrote:

谁能告诉我怎么样内容处理程序可以确定文件的编码吗?可以sax

提供此信息吗?
Can anyone tell me how the content handler can determine the encoding of the file? Can sax
provide this info?



内部没有编码一个XML文档;它是全部的Unicode。


< / F>

there is no encoding on the "inside" of an XML document; it''s all Unicode.

</F>


>任何人都可以告诉我如何内容处理程序可以确定
>Can anyone tell me how the content handler can determine the encoding of

>文件的编码?萨克斯可以提供此信息吗?
>the file? Can sax provide this info?


内部没有编码一个XML文档;这都是Unicode。
there is no encoding on the "inside" of an XML document; it''s all Unicode.



是的,但是sax正在读取文件,所以sax正在生成unicode,所以它b / b
应该(必须)能够确定编码。此外,xml文件

以以下行开头:


<?xml version =" 1.0" encoding =" utf-8"?>


所以sax能够以某种方式返回''utf-8'似乎是合理的。

我错过了什么吗?


爱德华

---------------------- ----------------------------------------------

Edward K. Ream电子邮件: ed*******@charter.net
Leo: http://webpages.charter.net/edreamleo /front.html

---------------------------------- ----------------------------------

True, but sax is reading the file, so sax is producing the unicode, so it
should (must) be able to determine the encoding. Furthermore, xml files
start with lines like:

<?xml version="1.0" encoding="utf-8"?>

so it would seem reasonable for sax to be able to return ''utf-8'' somehow.
Am I missing something?

Edward
--------------------------------------------------------------------
Edward K. Ream email: ed*******@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------


爱德华K. Ream写道:
Edward K. Ream wrote:

>>任何人都可以告诉我内容处理程序如何确定文件的编码?萨克斯可以提供此信息吗?
>>Can anyone tell me how the content handler can determine the encoding of
the file? Can sax provide this info?


>内部没有编码一个XML文档;它全部是Unicode。
>there is no encoding on the "inside" of an XML document; it''s all
Unicode.



是的,但是sax正在读取文件,因此sax正在生成unicode,因此它应该(必须)能够确定编码。


True, but sax is reading the file, so sax is producing the unicode, so it
should (must) be able to determine the encoding.



读取xml标题。

It is, by reading the xml header.


此外,xml文件

从以下行开始:


<?xml version =" 1.0" encoding =" utf-8"?>


所以sax能够以某种方式返回''utf-8'似乎是合理的。

我错过了什么吗?
Furthermore, xml files
start with lines like:

<?xml version="1.0" encoding="utf-8"?>

so it would seem reasonable for sax to be able to return ''utf-8'' somehow.
Am I missing something?



sax输出unicode,它不再有编码关联。因此

这是一个非常无关紧要的信息。它可以保留,但对于

有什么用途?


Diez

That sax outputs unicode, which has no encoding associated anymore. And thus
it is a pretty much irrelevant information. It _could_ be retained, but for
what purpose?

Diez


这篇关于如何向sax请求文件编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆