SimpleXML xpath within selected node

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

I have the following XML file

 
  ...
  ...   
      
    

        
2条回答
  •  天涯浪人
    2021-01-23 15:36

    Realtive to your context node $item (I have no doubt there's why you need that context node ;-)) you're looking for ImageSet that a) is a child of ImageSets (which in turn is a direct child of your context node) and b) has the attribute Category with the value primary (which you have coded correctly)

    xpath('ImageSets/ImageSet[@Category="primary"]') as $p) {
            echo $p->SwatchImage->URL;
        }
    }
    
    
    function data() {
        return <<< eox
    
        
          ...
          ...
          
            
              
                ...
                
                
              
              
                ...
                
                
              
            
            
              
                primary swatch image url
                
                
              
              
                ...
                
                
              
            
          
        
        ...
          
    eox;
    }
    

提交回复
热议问题