0

I'm building a list of nodes I need to load from XML document using SelectNodes(xpath):

Set oNodeList = xmldoc.selectNodes("//Object/Property[@Name='Group' and Value='True']") 

and looping thru the nodes:

For Each curNode In oNodeList Set nAttr = curNode.parentNode.Attributes If (nAttr.getNamedItem("Seq").nodeValue = "abc") Then ' additional processing End If Next 

Additional processing involves looping thru child nodes of curNode. I was wondering if it's possible in build yet another nodeList using selectNodes which would select child nodes of curNode that meet particular criteria. The key point that xpath should start looking from the current node.

How can I do that?

2
  • documentation isn't clear. From msdn.microsoft.com/en-us/library/aa220790(v=office.11).aspx it looks like you can call selectNodes method only for a Document class, but then in msdn.microsoft.com/en-us/library/aa212478(v=office.11).aspx there is a selectNodes method listed linked to the same documentation page. So, it's not posible to tell how selectNodes defines the context node. You could try calling this method from curNode. Also, you are performing some filtering inside For Each that looks like it could be done in the first XPath expression. Clarify that. Commented Nov 16, 2010 at 20:34
  • @Alejandro: Filtering in the For Each is what I'm doing now and of course it works but the code looks ugly. It would be much better if I could Xpath from current node. I know I could do it by adding [position()=nnn] to the original query (where nnn is curNode index) but again, it's ugly. I'm looking for xpath starting from current node! Commented Nov 16, 2010 at 20:38

1 Answer 1

1

Alejandro, thank you! It seems like

curNode.Selectnodes("child::*") 

does the trick!

Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad it helps you. Do note that * is a short form of child::*

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.