|
本人需要读取xml文件里WSXX节点的值,如下
<?xml version="1.0" encoding="GBK" ?>
- <tiripPackage version="1.0" xmlns="http://www.chinatax.gov.cn/tirip/dataspec">
- <![CDATA[
<?xml version="1.0" encoding="GBK"?>
<HDXX>
<NSRSBH>999999999999999</NSRSBH>
<SBZL>
<SBZLCODE>10102</SBZLCODE>
<SBZLMC>小规模增值税申报</SBZLMC>
<SBQJ>1</SBQJ>
<ZSXMBM></ZSXMBM>
<ZSXMPY></ZSXMPY>
<ZSXMMC>小规模增值税申报</ZSXMMC>
<WSXXS>
<WSXX>
<CODE>BQYJ</CODE>
<NAME>本期预缴金额</NAME>
<VALUE>2</VALUE>
</WSXX>
用tc帮助文档的example只能读取第一个<?xml version="1.0" encoding="GBK"?>下的节点,第二个<?xml version="1.0" encoding="GBK"?>下面的节点就读不到了
procedure TestWithXPath1;
var
Doc, s, Nodes, ChildNodes, i, Node : OleVariant;
begin
// Create COM object
Doc := Sys.OleObject('Msxml2.DOMDocument');
Doc.async := false;
// Load data from a file
// We use the file created earlier
Doc.load('C:\data1.xml');
// Report an error, if, for instance, the markup or file structure is invalid
if Doc.parseError.errorCode <> 0 then
begin
s := 'Reason:' + #9 + Doc.parseError.reason + #13#10 +
'Line:' + #9 + VarToStr(Doc.parseError.line) + #13#10 +
'Pos:' + #9 + VarToStr(Doc.parseError.linePos) + #13#10 +
'Source:' + #9 + Doc.parseError.srcText;
// Post an error to the log and exit
Log.Error('Cannot parse the document.', s);
Exit;
end;
//Use an XPath expression to obtain a list of "control" nodes
Nodes := Doc.selectNodes('//WSXX');//第一个xml头下可以读出来,第二个头下读不出来了
showmessage(Nodes.length);
// Process the node
for i := 0 to Nodes.length - 1 do
begin
// Get the node from the collection of found nodes
Node := Nodes.item(i);
// Get child nodes
ChildNodes := Node.childNodes;
// Output two child nodes to the log
Log.Message(ChildNodes.item(1).text + ': ' + ChildNodes.item(2).text);
end;
end;
各位大虾,有知道的帮忙下喔,谢谢谢谢拉
[ 本帖最后由 Astina 于 2010-6-21 12:24 编辑 ] |
|