求助PB解析XML的问题。。。我是菜鸟,劳烦各位高手了
是这样的,我有一个Data.xml文件 具体里面内容如下:
<xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<s:Schema id="RowsetSchema">...</s:Schema>
<rs:data>
<z:row id="51030200003101" clpzh="川C08677" cpys="黄色" clcp="解放牌" cpxh="CA4252P21K2T1A" cgzh="" fdjh="50655282" dph="LFWSRXNJ451A05459" ccrq="2006-03-01T00:00:00" csys="" rllx="柴油 " cldw=".000" gcrq="2006-03-01T00:00:00" jjlx="有限 " ickh=" " yy_dlyszh="0014268" yy_fzsj="2010-08-12T00:00:00" yy_jyfw="普通货运" yy_cyhz="" yy_yyzt="营运" yy_sfgkjy="" yy_sfcrj="True" yc_yczh="" yc_ycnr="" yc_ycfs="" cz_czxm="" cz_czdz="" cz_sfzh="" cz_bz="" cz_jsy1="" cz_jsy2="" cz_jsy3="" cz_fwzgzh1="" cz_fwzgzh2="" cz_fwzgzh3="" cz_dy_yh=" " cz_dy_bz="" cz_jyxkzh="510302000585" lock="0" username="杨玉康" yhbm="51030200000438" ssxs="51030200" ssdq="51030000" cx="大货" bclb="" yslb="牵引车" kcjb="" kclx="" sspq=" " nsrq="2011-09-16T00:00:00" nsjg="合格 " jsdj="二级车" jsdjpdrq="2011-09-16T00:00:00" jsdjyxrq="2012-09-13T00:00:00" jdrq="2006-11-14T00:00:00" jdqjl="" zlkhjg=" " bcewrq="2011-09-14T00:00:00" xcewrq="2011-12-14T00:00:00" dah="" csbz="0" cxbz="0" scbz="0" yxrq="2006-11-14T00:00:00" hdzzl="0" cc="6888" ck="2490" cg="3240" zqyzzl="35700.00" rowguid="{CAC6B4A5-9B61-4652-8C50-02D3E4C1A33B}" sfdy="1" print_ssxs="51030200" print_username="霍革军" print_date="2010-08-12T00:00:00" yhmc="自贡三辰实业有限公司" c112="51030200000438"/>
</rs:data>
</xml>
我想得到<rs:data>和</rs:data>之间的内容(汉字不能是乱码),我之前用fileopen读出来函子就是乱码,PBdom 用的也很不熟悉,由于 <xml xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">与</xml>这个跟节点不是规则对应的,所以一直无法读出中间的数据,还请各位大哥高手帮个忙,下周就要用了,最好有例子给小弟看看,参考一下,不胜感谢。在线等,qq联系也行524889033,谢谢了
[解决办法]
用FileOpen时注意打开的编码格式,你要先确认XML文件的具体编码格式是什么,然后才能正确读取里面的文本。 FileOpen函数原型:
-------------------------
FileOpen ( filename {, filemode {, fileaccess {, filelock {, writemode { encoding }}}}} )
filename
A string whose value is the name of the file you want to open. If filename is not on the current directory's relative search path, you must enter the fully qualified name.
filemode (optional)
A value of the FileMode enumerated type that specifies how the end of a file read or file write is determined. Values are:
LineMode! – (Default) Read or write the file a line at a time
StreamMode! – Read blocks of binary data
TextMode! – Read text blocks
For more information, see Usage below.
fileaccess
(optional)
A value of the FileAccess enumerated type that specifies whether the file is opened for reading or writing. Values are:
Read! – (Default) Read-only access
Write! – Write-only access
If PowerBuilder does not find the file, a new file is created if the fileaccess argument is set to Write!
filelock (optional)
A value of the FileLock enumerated type specifying whether others have access to the opened file. Values are:
LockReadWrite! – (Default) Only the user who opened the file has access
LockRead! – Only the user who opened the file can read it, but everyone has write access
LockWrite! – Only the user who opened the file can write to it, but everyone has read access
Shared! – All users have read and write access.
writemode (optional)
A value of the WriteMode enumerated datatype. When fileaccess is Write!, specifies whether existing data in the file is overwritten. Values are:
Append! – (Default) Write data to the end of the file
Replace! – Replace all existing data in the file
Writemode is ignored if the fileaccess argument is Read!
encoding
Character encoding of the file you want to create. Specify this argument when you create a new text file using text or line mode. If you do not specify an encoding, the file is created with ANSI encoding. Values are:
EncodingANSI! (default)
EncodingUTF8!
EncodingUTF16LE!
EncodingUTF16BE!
[解决办法]
如果用pb10的话,直接用fileopen打开,直接读即可
如果用pb8和pb9的话,用fileopen打开后,把数据读到变量里,然后用lenw,leftw,midw来处理就不会有乱码了
[解决办法]
这个<rs:data>和</rs:data>之间的内容不是标准的xml文档,你就别试pbdom了,还是自己解析吧