XPATH - Select all child nodes with a specific attribute

前端 未结 2 661
星月不相逢
星月不相逢 2021-01-13 03:36

What would be the xpath query to find all child nodes with a specific attribute value, but starting from a node with a specific attribute value?

This is kind of rela

相关标签:
2条回答
  • 2021-01-13 04:27

    HI Chris sorry but that isnt quite working for me. If you run my following code:

        $dom = new DomDocument;
    $dom->load('http://rdfs.org/sioc/ns#');
    $xpath = new DOMXPath($dom);
    
    $elements = array();
    foreach($xpath->query('//@rdf:about') as $element) {
    
        array_push($elements, $element->value);
    }
    
    foreach($elements as $element) {
    
        echo("<br />" . $element);
    }
    

    You should get a list of elements in the sioc ontology. The problem is that the first 9 are not actually part of the ontology and so I want to ignore them and start on the 10th node which has 'http://rdfs.org/sioc/ns#' as its value for the rdf:about attribute.

    By including your xpath query i get nothing back at all.

    0 讨论(0)
  • 2021-01-13 04:29
    $xpath->query("//*[@rdf:about='http://rdfs.org/sioc/ns#']/following-sibling::*/@rdf:about");

    With your sample script, outputs URLs starting/ending with:

    http://rdfs.org/sioc/ns#Community
    http://rdfs.org/sioc/ns#Container
    ...
    http://rdfs.org/sioc/ns#reference
    http://rdfs.org/sioc/ns#subject
    0 讨论(0)
提交回复
热议问题