亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
12下一頁
最近訪問板塊 發(fā)新帖
查看: 12703 | 回復(fù): 16
打印 上一主題 下一主題

xml文件的中文問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2003-06-17 20:31 |只看該作者 |倒序瀏覽
PERL的xml:arser 有支持gbk或gb2312 charset 的嗎?
缺省只有big5。

讀包含中文的xml文件,我這樣寫
     
<?xml version="1.0" encoding="big5"?>;

<ETLConfig>;
    <database S="test" U="測試" P="測試"/>;
    <database S="aaa" U="aaa" P="aaa"/>;
</ETLConfig>;

輸出的是亂碼。
use XML::Simple;
use Data:umper;

my $config = XMLin('c:/server.xml');          # load the file

print Dumper($config);
use bytes;

print  $config->;{database}[0]->;{U};                             
no bytes;

論壇徽章:
1
榮譽會員
日期:2011-11-23 16:44:17
2 [報告]
發(fā)表于 2003-06-18 08:41 |只看該作者

xml文件的中文問題

應(yīng)該跟encode沒關(guān)係..我沒用過XML::Simple
但是XML::Simple是外國人寫的...所以不可能
default用big5的...
Default應(yīng)該是utf8...或其它的...
試試看把下面這行改成
<?xml version="1.0" encoding="gb2312"?>;
看看...
Perl有本Perl and XML的書..我覺得字太小一直沒看...
看了兩頁就放棄了...
去找找有沒有電子書翻翻吧..

論壇徽章:
0
3 [報告]
發(fā)表于 2003-06-18 15:20 |只看該作者

xml文件的中文問題

沿著前人的路走了一遍,得出的結(jié)果和他的一樣。難道這條路沒人走通過嗎?

The XML:arser installed from CPAN does not come with a
GB2312 encoding support. However, I was not able to add
the support as instructed by the XML::Encoding package.

To add this support, I did the following:

1. Download GB2312.TXT from ftp.unicode.org
2. Download the XML::Encoding 1.01 and get two binaries:
   make_encmap and compile_encoding
3. run make_encmap as follows:
   make_encmap GB2312 GB2312.TXT >; GB2312.encmap
4. Add expat='yes' to the first line of GB2312.encmap
5. run compile_encoding:
   compile_encoding -o GB2312.enc GB2312.encmap
6. copy GB2312.enc to
   /usr/lib/perl5/site_perl/5.005/i386-linux/XML/Parser/Encodings

Then I made the following perl script:
---------------
#!/usr/bin/perl
use XML:arser;

my $xmlfile = $ARGV[0];
my $parser = new XML:arser();
my $doc = $parser->;parsefile ("$xmlfile";
---------------

I run this script with a well-formed xml file having a head line
as: <?xml version="1.0" encoding="GB2312"?>;

Following error occurs:

unknown encoding at line 1, column 30, byte 30 at /usr/lib/perl5/site_perl/5.005/i386-linux/XML/Parser.pm line 185

Changing the encoding to other supported ones seem to work without error.
I'm wondering if there is something I'm missing in the process.

Thanks for any suggestions!

論壇徽章:
1
榮譽會員
日期:2011-11-23 16:44:17
4 [報告]
發(fā)表于 2003-06-19 08:45 |只看該作者

xml文件的中文問題

會不會是大小寫的問題...改成
gb2312.enc
我剛剛檢查過
/usr/local/lib/perl5/site_perl/5.6.1/aix/XML/Parser/Encodings
這個目錄下:
-r--r--r--   1 root     system      4821 Feb 14 2000  Japanese_Encodings.msg
-r--r--r--   1 root     system      1946 Feb 14 2000  README
-r--r--r--   1 root     system     40706 May 10 2000  big5.enc
-r--r--r--   1 root     system     45802 May 10 2000  euc-kr.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-2.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-3.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-4.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-5.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-7.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-8.enc
-r--r--r--   1 root     system      1072 May 10 2000  iso-8859-9.enc
-r--r--r--   1 root     system      1072 May 10 2000  windows-1250.enc
-r--r--r--   1 root     system     37890 May 10 2000  x-euc-jp-jisx0221.enc
-r--r--r--   1 root     system     37890 May 10 2000  x-euc-jp-unicode.enc
-r--r--r--   1 root     system     20368 May 10 2000  x-sjis-cp932.enc
-r--r--r--   1 root     system     18202 May 10 2000  x-sjis-jdk117.enc
-r--r--r--   1 root     system     18202 May 10 2000  x-sjis-jisx0221.enc
-r--r--r--   1 root     system     18202 May 10 2000  x-sjis-unicode.enc

都是小寫...
另外..你可以在.pl前頭加上...
use Carp();
local $SIG{__WARN__} = \&Carp::cluck;

Trace一下..看到底是哪裡一行出問題..
185行是parse,他後面還有call其他function..
不然..實在看不出來哪兒出錯了...

論壇徽章:
0
5 [報告]
發(fā)表于 2003-06-19 18:00 |只看該作者

xml文件的中文問題

大寫改成小寫了,但還是同樣的錯。
gb2312.TXT見http://www.unicode.org/Public/MAPPINGS/OBSOLETE/EASTASIA/GB/
能不能幫忙看一下。

論壇徽章:
1
榮譽會員
日期:2011-11-23 16:44:17
6 [報告]
發(fā)表于 2003-06-19 19:12 |只看該作者

xml文件的中文問題

http://aspn.activestate.com/ASPN/Mail/Message/perl-xml/937990
http://lists.xml.org/archives/xml-dev/200208/msg01661.html
http://www.xml.com/pub/a/1999/09/expat/index.html

看看吧...
看起來是因為expat不支援gb2312..
所以你可能要先轉(zhuǎn)碼成utf8..
或者用他上面所提的另一個Parser
或者..改寫XML:arser..讓他支援gb2312...

論壇徽章:
0
7 [報告]
發(fā)表于 2003-06-20 22:26 |只看該作者

xml文件的中文問題

expat的最新版本有很大的變化,不知道它怎樣被perl調(diào)用的.

www.sourceforge.net/projects/expat

Expat is a library, written in C, for parsing XML documents. It's the underlying XML parser for the open source Mozilla project, Perl's XML:arser, Python's xml.parsers.expat, and other open-source XML parsers.

論壇徽章:
1
榮譽會員
日期:2011-11-23 16:44:17
8 [報告]
發(fā)表于 2003-06-22 11:37 |只看該作者

xml文件的中文問題

我試著去Trace XML:arser這個module...
不過看到蠻多看不懂的東西..
他裡面有用到
XML:arser::Expat這個module..
在XML:arser::Expat這個module中有個
load_encoding的function,是當(dāng)Expat module
找不到相關(guān) encoding時會自動呼叫,
我試著依照document的方式自己Load
gb2312.enc,[其中LoadEncoding的結(jié)果,可以得到正確的
GB2312,但是在相對應(yīng)的%Encoding_Table中卻無法得到
這個gb2312.enc的編碼,因此才無法支援gb2312的編碼


  1. local(*ENC);
  2. open(ENC, $file) or croak("Couldn't open encmap $file:\n$!\n");
  3. binmode(ENC);
  4. my $data;
  5. my $br = sysread(ENC, $data, -s $file);
  6. croak("Trouble reading $file:\n$!\n")
  7.    unless defined($br);
  8. close(ENC);

  9. my $name = LoadEncoding($data, $br);
  10. #print "$name\n";
  11. croak("$file isn't an encmap file")
  12.    unless defined($name);
復(fù)制代碼


現(xiàn)在問題縮小到LoadEncoding($data,$br);
這行,可以正確的讀出GB2312編碼,但是卻無法存入
%Encoding_Table中,
這個LoadEncoding function 我還沒找到在哪裡...
有興趣的人可以follow下去...

論壇徽章:
0
9 [報告]
發(fā)表于 2003-06-22 11:59 |只看該作者

xml文件的中文問題

LoadEncoding函數(shù)是C代碼。
在XML-Parser-2.31的Expat.c中。

論壇徽章:
1
榮譽會員
日期:2011-11-23 16:44:17
10 [報告]
發(fā)表于 2003-06-23 08:41 |只看該作者

xml文件的中文問題

應(yīng)該是Expat/Expat.xs裡面...XML_LoadEncoding function...
我C的功力還沒那麼好...所以可能得找C的高手幫忙看看..
因為他會產(chǎn)生一個Expat.so的share object在auto/XML/Parser/Expat目錄下,
可以直接蓋掉上面目錄中的那個...或者重新安裝XML:arser...
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP