XML文件如下:<?xml version="1.0" encoding="GB2312"?>
<ASDF>
<Attribute ServerIP="" IsStart="false"/>
<DN>
<Res Desc="Tools1">
<DNList>
<ComplexDN StartDN="0001" EndDN="0001"/>
</DNList>
<RunTime>
<RunPeriod Begin="0" End="1">
<Application Name="ASD" XMLFile="a.exe" Isbound="true" IsAutoStart="false"/>
</RunPeriod>
</RunTime>
</Res><Res Desc="Tools2">
<DNList>
<ComplexDN StartDN="1001" EndDN="1001"/>
</DNList>
<RunTime>
<RunPeriod Begin="0" End="1">
<Application Name="ASD" XMLFile="b.exe" Isbound="true" IsAutoStart="false"/>
</RunPeriod>
</RunTime>
</Res>
        
</DN>
</ASDF>如上文件中有两个重复的<Res ...></Res>节点,如何能够分别取到各自子节点的值呢?
比如需要:
<Res Desc="Tools1">
<DNList>
<ComplexDN StartDN="0001" EndDN="0001"/>
</DNList>
<RunTime>
<RunPeriod Begin="0" End="1">
<Application Name="ASD" XMLFile="a.exe" Isbound="true" IsAutoStart="false"/>
</RunPeriod>
</RunTime>
</Res>中的StartDN和
<Res Desc="Tools2">
<DNList>
<ComplexDN StartDN="1001" EndDN="1001"/>
</DNList>
<RunTime>
<RunPeriod Begin="0" End="1">
<Application Name="ASD" XMLFile="b.exe" Isbound="true" IsAutoStart="false"/>
</RunPeriod>
</RunTime>
</Res>中的StartDN的值呢?

解决方案 »

  1.   

    搞定了
    procedure TForm1.Button2Click(Sender: TObject);
    var
            mStr: string;
            i,j: integer;
            mRootNode,mChildNode:IXMLNode;
    begin
            mXml.LoadFromFile('d:\test.xml');
            mXml.Active := True;
            mRootNode := mXml.DocumentElement;        mChildNode := mRootNode.ChildNodes['DN'].ChildNodes['Res'].NextSibling;
            mStr := mChildNode.AttributeNodes['Desc'].Text;
            ShowMessage(mStr);
    end;后面的你应该会写了吧,呵呵。
      

  2.   

    谢谢,已经可以实现,
    不过还有个疑问,我应该如何去判断NextSibling;是否存在呢?
      

  3.   

    根据mChildNode.ParentNode.ChildNodes.Count的数值,可以知道有几个子结点。