HighTechTalks DotNet Forums  

Variable in XPath?

Dotnet XML microsoft.public.dotnet.xml


Discuss Variable in XPath? in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
a
 
Posts: n/a

Default Variable in XPath? - 06-30-2006 , 04:27 AM






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



Reply With Quote
  #2  
Old   
a
 
Posts: n/a

Default Re: Variable in XPath? - 06-30-2006 , 05:31 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 (AT) microsoft (DOT) com> escribió en el mensaje
news:eN2QCtCnGHA.5056 (AT) TK2MSFTNGP04 (DOT) phx.gbl...
Quote:
why you can't do this?

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


"a" <hans (AT) georg (DOT) de> escribió en el mensaje
news:e82qpi$278$1 (AT) montagut (DOT) cesca.es...
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







Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.