SimpleXML xpath within selected node

后端 未结 2 545
栀梦
栀梦 2021-01-23 14:49

I have the following XML file

 
  ...
  ...   
      
    

        
2条回答
  •  说谎
    说谎 (楼主)
    2021-01-23 15:27

    You have an error in the XPath expression. If the expression starts with an / it is relative to the document itself. You want it relative to the current node. This means you have two possible solutions

    ImageSet[@Category="primary"]

    This expands to child::ImageSet. It fetches the ImageSet element nodes that are direct children of the context node.

    .//ImageSet[@Category="primary"]

    Expands and normalizes to descendant::ImageSet. It fetches any ImageSet inside the current context, even if it is not a direct child. The . represents the current node and // changes the axis to descendants.

提交回复
热议问题