RE: XML Parsing Help
- From: v-phuang@xxxxxxxxxxxxxxxxxxxx ("Peter Huang" [MSFT])
- Date: Thu, 21 Apr 2005 06:21:04 GMT
Hi
I think we can use XPath to locate the Node we want and then enumerate its
children node.
Assume we have xml file as below.
[Test.xml]
<?xml version="1.0" encoding="utf-8" ?>
<Customers>
<Customer>
<CustomerNumber>C2000</CustomerNumber>
<CustomerName>Demo Customer 2</CustomerName>
<CustCredit>
<Amount>2000</Amount>
</CustCredit>
<CustCredit>
<Amount>3000</Amount>
</CustCredit>
</Customer>
<Customer>
<CustomerNumber>C1000</CustomerNumber>
<CustomerName>Demo Customer 1</CustomerName>
</Customer>
</Customers>
[VB.NET]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim xml As New Xml.XmlDocument
xml.Load("..\Test.xml")
Dim xmlNode As Xml.XmlNode =
xml.SelectSingleNode("//Customer[./CustomerName/text()='Demo Customer 2']")
Dim xmlNodes As Xml.XmlNodeList =
xmlNode.SelectNodes("./CustCredit")
MsgBox(xmlNodes.Count)
If xmlNodes.Count > 0 Then
For Each xn As Xml.XmlNode In xmlNodes
MsgBox(xn.FirstChild.InnerText)
Next
End If
Dim xmlNode1 As Xml.XmlNode =
xml.SelectSingleNode("//Customer[./CustomerName/text()='Demo Customer 1']")
Dim xmlNodes1 As Xml.XmlNodeList =
xmlNode1.SelectNodes("./CustCredit")
MsgBox(xmlNodes1.Count)
End Sub
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- References:
- XML Parsing Help
- From: Mitchell Vincent
- XML Parsing Help
- Prev by Date: Re: Forms refresh
- Next by Date: Re: XML Parsing Help
- Previous by thread: XML Parsing Help
- Next by thread: Re: XML Parsing Help
- Index(es):