Nov 12, 2007

Using XPath and Xdoc In Xml Documents

'// sample xml

Dim sb As New System.Text.StringBuilder
sb.Append("")
sb.Append("1000")
sb.Append("1")
sb.Append("07.11.2007")
sb.Append("31.12.9999")
sb.Append("GARTENSTR. 66")
sb.Append("")
sb.Append("76031")
sb.Append("KARLSRUHE")
sb.Append("DE")
sb.Append("")
sb.Append("721121212")
sb.Append("
")



Dim xDoc As New XmlDocument
xDoc.LoadXml(_InputXML)

'// Get Attribute
Dim tcode As String = xDoc.FirstChild.LocalName
Dim profile As String = xDoc.FirstChild.Attributes.GetNamedItem("profile").InnerText
Dim rfcname As String = xDoc.FirstChild.Attributes.GetNamedItem("rfcname").InnerText
Dim cpuid As String = xDoc.FirstChild.Attributes.GetNamedItem("cpuid").InnerText
Dim role As String = xDoc.FirstChild.Attributes.GetNamedItem("role").InnerText
Dim desc As String = xDoc.FirstChild.Attributes.GetNamedItem("desc").InnerText

' Dim doc As XPathDocument
Dim nav As XPathNavigator
Dim iter As XPathNodeIterator

'doc = New XPathDocument(_InputXML)
'nav = doc.CreateNavigator
nav = xDoc.CreateNavigator
iter = nav.Select("/") 'Your node name goes here


While iter.MoveNext
Dim iterNews As XPathNodeIterator
iterNews = iter.Current.SelectDescendants(XPathNodeType.Element, False)
While iterNews.MoveNext
' Debug.WriteLine(iterNews.Current.Name & ": " & iterNews.Current.Value)
If Not iterNews.CurrentPosition = 1 Then
SFO.Exports(iterNews.Current.Name).Value = iterNews.Current.Value
End If

End While
End While

dim sPERNR as string = xDoc.GetElementsByTagName("PERNR").Item(0).InnerText

No comments:

Post a Comment