Discussion:
Xpath problem in XMLdocument SelectNodes
(too old to reply)
Chris
2007-01-20 21:02:29 UTC
Permalink
I have the following XML file that I am trying to navigate in an
xmldocument. I want to loop through the placeholders and then do a nested
loop through the properties. My code looks a little like this:
My second xpath expression doesn't return any nodes. What am I doing wrong?
The commented out expression does return something but I would that would
return all property nodes not just the ones that belong to the parent.

placeholder_nodelist =
xmlconfig.SelectNodes("/presentation/placeholders/placeholder")

For Each placeholder_node In placeholder_nodelist
Do stuff

'controlnodelist =
xmlconfig.SelectNodes("/presentation/placeholders/placeholder/properties/property")
controlnodelist = xmlconfig.SelectNodes("./properties/property")

For Each controlnode In controlnodelist
next
next

<presentation formname="form1">
<formname>form1</formname>
<placeholders>
<placeholder>
<placeholdername>plformgroup</placeholdername>
<properties>
<property><propertyname>userid</propertyname></property>
</properties>
</placeholder>

<placeholders>
<placeholder>
<placeholdername>plformgroup</placeholdername>
<properties>
<property><propertyname>userid</propertyname></property>
</properties>
</placeholder>
</presentation>
Dimitre Novatchev
2007-01-21 05:17:34 UTC
Permalink
Post by Chris
For Each placeholder_node In placeholder_nodelist
Do stuff
'controlnodelist =
xmlconfig.SelectNodes("/presentation/placeholders/placeholder/properties/property")
controlnodelist = xmlconfig.SelectNodes("./properties/property")
Shouldn't the last line be:

controlnodelist = placeholder_node
.SelectNodes("./properties/property")



Cheers,
Dimitre Novatchev
Post by Chris
I have the following XML file that I am trying to navigate in an
xmldocument. I want to loop through the placeholders and then do a nested
My second xpath expression doesn't return any nodes. What am I doing
wrong? The commented out expression does return something but I would that
would return all property nodes not just the ones that belong to the
parent.
placeholder_nodelist =
xmlconfig.SelectNodes("/presentation/placeholders/placeholder")
For Each placeholder_node In placeholder_nodelist
Do stuff
'controlnodelist =
xmlconfig.SelectNodes("/presentation/placeholders/placeholder/properties/property")
controlnodelist = xmlconfig.SelectNodes("./properties/property")
For Each controlnode In controlnodelist
next
next
<presentation formname="form1">
<formname>form1</formname>
<placeholders>
<placeholder>
<placeholdername>plformgroup</placeholdername>
<properties>
<property><propertyname>userid</propertyname></property>
</properties>
</placeholder>
<placeholders>
<placeholder>
<placeholdername>plformgroup</placeholdername>
<properties>
<property><propertyname>userid</propertyname></property>
</properties>
</placeholder>
</presentation>
Loading...