all groups > dotnet xml > june 2006 >
You're in the

dotnet xml

group:

Variable in XPath?


Variable in XPath? a
6/30/2006 12:00:00 AM
dotnet xml:
I'm trying to read a XML document with the following XPath code (programming
in VB .net):

Dim doc As XmlDocument = New XmlDocument()

doc.Load("c:\la2.xml")

Dim wort As XmlNode

Dim root As XmlElement = doc.DocumentElement

wort = root.SelectSingleNode("descendant::e[id='2']")



The single node selected has an element called ID and numbered 2. The
problem is: this number 2 has to be a variable number coming from another
source. How can I code



wort = root.SelectSingleNode("descendant::e[id='2']")

in the following way (pseudoicode)

wort = root.SelectSingleNode("descendant::e[id='HERE MUST COME A
VARIABLE']")



Any suggestion to solve this problem is welcome!





Oliver

Re: Variable in XPath? Mario Vázquez
6/30/2006 12:00:00 AM
why you can't do this?

wort = root.SelectSingleNode("descendant::e[id='" & <YourVariable> & "'")


"a" <hans@georg.de> escribió en el mensaje
news:e82qpi$278$1@montagut.cesca.es...
[quoted text, click to view]

Re: Variable in XPath? a
6/30/2006 12:00:00 AM
That was it. Meanwhile, I found a workari¡ound with a compiled expression,
but your solution is more elegant. Thanks

Oliver

"Mario Vázquez" <alguien@microsoft.com> escribió en el mensaje
news:eN2QCtCnGHA.5056@TK2MSFTNGP04.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button