Groups | Blog | Home
all groups > dotnet xml > june 2004 >

dotnet xml : Path of an XML node


Derek Harmon
6/29/2004 7:38:18 PM
[quoted text, click to view]

I take it there is a Categories node beneath Games that is the one
you selected? (btw, element names can't include spaces.)

- - - ParentNodePath.vb (excerpt)
' . . .
Dim xn As XmlNode = xmlDoc.SelectSingleNode( "//Category")
If ( xn Is Not Nothing ) Then
' Import StringBuilder from System.Text
Dim buf As StringBuilder = New StringBuilder( 256)
xn = xn.ParentNode
While ( ( xn Is Not Nothing ) And ( xn.ParentNode Is Not Nothing ) )
buf.Insert( 0, '\')
buf.Insert( 0, xn.Name)
n = n.ParentNode
End While
End If
Dim parentPath As String = buf.ToString( )
' . . .
- - -

Assuming it finds a Category element in a node tree resembling your
example, parentPath will easily contain:

Categories\VideoGames\Nintendo64\Games\


Derek Harmon

The Clansman
6/29/2004 8:04:49 PM
Hi,
how do I get the path of an XML node?

I have:

Dim xmlNo As XmlNode = xml.SelectSingleNode("//Category[@Id='" & CategoryID
& "']")

I want to get the path of the xmlNo:

i.e.
Categories\Video games\Nintendo 64\Games\



thanks,
Bruno

The Clansman
6/29/2004 9:57:56 PM
Thanks man!!

yes, its VideoGames

Bruno

[quoted text, click to view]

AddThis Social Bookmark Button