a recursive walk through XPathNavigator

Sub RecursiveWalkThroughXpath(ByVal oNavigator As XPathNavigator)
Select Case oNavigator.NodeType
Case XPathNodeType.Element
If oNavigator.Prefix = String.Empty Then
Console.WriteLine(“<{0}>”, oNavigator.LocalName)
Else
Console.Write(“<{0}:{1}>”, oNavigator.Prefix, oNavigator.LocalName)
Console.WriteLine(vbTab + oNavigator.NamespaceURI)
End If
Case XPathNodeType.Text
Console.WriteLine(vbTab + oNavigator.Value)
End Select

If oNavigator.MoveToFirstChild() Then
Do
RecursiveWalkThroughXpath(oNavigator)
Loop While (oNavigator.MoveToNext())

oNavigator.MoveToParent()
If (oNavigator.NodeType = XPathNodeType.Element) Then
Console.WriteLine(“</{0}>”, oNavigator.Name)
End If
Else
If oNavigator.NodeType = XPathNodeType.Element Then
Console.WriteLine(“</{0}>”, oNavigator.Name)
End If
End If
End Sub

..:: Whereever you go, stay in touch. Download toolbar now! It´s free, private and secure. ::..

get namespaces from xml with help of XPathNavigator

Dim sXmlFragment As String = oDom.FirstChild.ChildNodes(0).OuterXml
Dim oXDom As New XPathDocument(New StringReader(sXmlFragment))
Dim oXPN As XPathNavigator = oXDom.CreateNavigator()
oXPN.MoveToFollowing(XPathNodeType.Element)
Dim oNamespaces As IDictionary(Of String, String) = oXPN.GetNamespacesInScope(XmlNamespaceScope.All)
Dim sSchemaNamespace As String = String.Empty
For Each de As KeyValuePair(Of String, String) In oNamespaces
oNsmgr.AddNamespace(de.Key, de.Value)
Next

..:: Whereever you go, stay in touch. Download toolbar now! It´s free, private and secure. ::..