Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.Xml.XPath

Status
Not open for further replies.

krionic

Programmer
Jun 5, 2004
6
US
Hello, I sure do hope there are some XPath/XML gurus out here. I'm pretty new to working with XML in .net So I'm sure my problem is I just dont know how to do what I'm trying to do

XML File
Code:
<Data>
  <Employees>
    <ID>1</ID>
    <Name>Krionic</Name>
  </Employees>
</Data>

XPath Reader
Code:
Dim strXPathFile As String
Dim XPathExp As XPathExpression
Dim nav As XPathNavigator
Dim docNav As XPathDocument
Dim NodeIter As XPathNodeIterator
Dim strXPathQuery As String

strXPathFile = "C:/XMLFile.xml"
strXPathQuery = "/Data/Employees"

docNav = New XPathDocument(strXPathFile)
nav = docNav.CreateNavigator
XPathExp = nav.Compile(strXPathQuery)
NodeIter = nav.Select(XPathExp)
nav.MoveToFirstChild()
NodeIter.MoveNext()

Ok, the problem I'm running in to is how the data is being brought to me

If I do
Code:
NodeIter.Current.Value

The results will be "1Krionic". It is combining both the <ID> and <Name> child node to the value. There has got to be a way for me to get each 'child node' or 'column' for the Employee node.

I'd have thought I could do something like:
Code:
NodeIter.Current.ChildNode(0).Value
NodeIter.Current.ChildNode(1).Value
But thats not proper syntax to say the least and I dont see any other methods associated with XPathNodeIterator

If someone can point me to an example of what I'm trying to do or just point me in the right direction, I'd appreciate it. As of right now I'm just doing two querys to get each child node by setting the queryString to "/Data/Employees/ID" and then doing it again "/Data/Employees/Name". But thats not very efficient if I needed build an array or collection if my Employees had 50 different types of information I needed to gather like Address and Age and Sex and well, you get the picture.

I'm open to any suggestions also. Maybe I could format my XML file differently? Using the wrong XML functions?

Anyway, thanks for any help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top