result of xpath in dataset

Droomgans

Member
Joined
Aug 29, 2007
Messages
8
Programming Experience
Beginner
Hi everybody

I have a big xml-file, I want to do a xpath-query on that file so I just keep the part that I want, and then I want to read that node into a dataset...

:)

what I tried is :
VB.NET:
Dim xpathDoc As XPathDocument
Dim xmlNav As XPathNavigator
Dim xmlNI As XPathNodeIterator
xpathDoc = New XPathDocument("C:\test.xml")
xmlNav = xpathDoc.CreateNavigator()
xmlNI = xmlNav.Select("descendant::NP[NR='" & mynr & "']")


the xml-file contains hundreds of NP nodes, but I just want the one I need in my dataset

mydataset.readxml(xmlni) doesn't work

anyone an idea how to get started? thx in advance

grtz
 
Last edited by a moderator:
The nodeset needs at least a root node to be considered a xml document. With XmlWriter you can write this and each node to form a new document.
VB.NET:
Dim writer As Xml.XmlWriter = Xml.XmlWriter.Create("dataout.xml")
writer.WriteStartElement("root2")
While xmlNI.MoveNext
    xmlNI.Current.WriteSubtree(writer)
End While
writer.WriteEndElement()
writer.Close()

'ds.ReadXml("dataout.xml")
 
Back
Top