这种格式的XML文件如何取值?
<?xml version="1.0" encoding="gb2312"?>
<TYFP Ver="1">
<Head>
<NSRSBH>310223564846112</NSRSBH>
<NSRMC>发票企业名称</NSRMC>
<SCSJ>20121102 10:12:07</SCSJ>
<SCFS>2</SCFS>
</Head>
<FPSY>
<KSSJ>20121001 00:00:00</KSSJ>
<JSSJ>20121031 23:59:59</JSSJ>
<JLS>1</JLS>
<ZPFS>1</ZPFS>
<ZPJE>10500.00</ZPJE>
<FPFS>0</FPFS>
<TPFS>0</TPFS>
<TPJE>0.00</TPJE>
<YSFS>0</YSFS>
<JXFS>0</JXFS>
</FPSY>
<KP RecNum="1">
<KPZL KPZLDM="21233" RecNum="1">
<KPJL>
<FPDM>131001223351</FPDM>
<FPHM>00408007</FPHM>
<KPLX>0</KPLX>
<KPRQ>20121005 12:48:35</KPRQ>
<HYFLDM>26</HYFLDM>
<JE>10500.00</JE>
<SKRMC>发票企业名称</SKRMC>
<SKRSH>发票企业名称</SKRSH>
<FKRMC>抬头企业名称</FKRMC>
<FKRSH>310225431157857</FKRSH>
<BZ2>2012年09月份业务费</BZ2>
<KPRXM>开票人</KPRXM>
<FHRXM>发货人</FHRXM>
<FPMX RecNum="2" HJJE="10500.00">
<Row XH="1" HPMC="业务费" JLDW="*" SL="1" DJ="10000" JE="10000.00" />
<Row XH="2" HPMC="业务费" JLDW="*" SL="1" DJ="500" JE="500.00" />
</FPMX>
</KPJL>
</KPZL>
</KP>
</TYFP>
想取:
<Row XH="1" HPMC="业务费" JLDW="*" SL="1" DJ="10000" JE="10000.00" />
<Row XH="2" HPMC="业务费" JLDW="*" SL="1" DJ="500" JE="500.00" />
的值。
[最优解释]
Dim doc As Xml.XmlDocument = New XmlDocument
Dim rootNode As XmlNode
Dim node As XmlNode
Dim nodes As XmlNodeList
doc.Load("C:\a.xml")
rootNode = doc.SelectSingleNode("TYFP")
node = rootNode.SelectSingleNode("KP")
nodes = node.SelectNodes("KPZL/KPJL/FPMX/Row")
For Each n As XmlNode In nodes
MsgBox(n.Attributes("XH").Value)
Next