Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

have this code:

$products   =   $feed->_xpath->query( "//cf:vehicle"  );

foreach( $products as $product )
{
    echo $product->nodeName . ': ' . $product->getAttribute('code') . '<br />';
    $imgs   =   $feed->_xpath->query( "//cf:image" , $product );
    echo '&nbsp;Imgs: ' . $imgs->length . '<br />';
}

the number of product nodes found in the xmlfeed is 103 - that is correct.

the query to locat images within that node however is NOT doing so within the current node context - it finds 116 image nodes which is the total number of image nodes within the feed where as it should only select the images within the current product (between 0 and 3 in most cases)

Any pointers muchly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
464 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to use .//cf:image to make it relative to the context node.

From http://www.w3.org/TR/xpath/#path-abbrev:

//para selects all the para descendants of the document root and thus selects all para elements in the same document as the context node

and

.//para selects the para element descendants of the context node

Also see http://bugs.php.net/bug.php?id=34413


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...