开发者

XPATH Query Recursion

开发者 https://www.devze.com 2023-01-13 05:03 出处:网络
I have an XML Document with Nodes that can appear recursively within other nodes of the same type. For example:

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 ab开发者_如何学Gole 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


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

//Category[CategoryId=1]
0

精彩评论

暂无评论...
验证码 换一张
取 消