tags:

views:

11

answers:

1

I have an XML Document with Nodes that can appear recursively within other nodes of the same type. For example:

<root>
   <Categories>
   <Category>
      <CategoryId>1</CategoryId>
      <CategoryName>Cat 1</CategoryName>
      <ChildCategories>
          <Category>
               <CategoryId>3</CategoryId>
               <CategoryName>Cat 3</CategoryName>
          </Category>
      </ChildCategories>
   </Category>
   <Category>
        <CategoryId>5</CategoryId>
        <CategoryName>Cat 5 </CategoryName>
   </Category>
   </Categories>
</root>

As such, I need to be able to query for a specific Category or Child Category (or even Child of a Child, etc) by its CategoryID value. Is this doable in XPATH?

TIA

+2  A: 

No problem. Use // to search the entire XML document and square brackets to filter by category id:

//Category[CategoryId=1]
John Kugelman
Awesome. Thanks.
Goblyn27