开发者

XPATH Query Recursion

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜