用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;