0

Here is the URL of the xml source:

I'm tryng to grab all the RichText elements using xpath relative location and then print the elementID attribute. It is outputting nothing though. Any ideas?

<?php  

$url = "FXG";    
$xml = simplexml_load_file($url);     
//print_r($xml);    
$textNode = $xml->xpath("//RichText");    
$count = count($textNode);    
$i = 0;    
while($i < $count)
{    
   echo '<h1>'.$textNode[$i]['s7:elementID'].'</h1>';
   $i++;
}    

?>
4

2 回答 2

1

You need to register the namespaces that are set in the xml

$url = "http://testvipd7.scene7.com/is/agm/papermusepress/HOL_12_F_green?&fmt=fxgraw";    
$xml = simplexml_load_file($url);       
$xml->registerXPathNamespace('default', 'http://ns.adobe.com/fxg/2008');
$xml->registerXPathNamespace('s7', 'http://ns.adobe.com/S7FXG/2008');
$textNode = $xml->xpath("//default:RichText/@s7:elementID");
foreach($textNode as $node) {
    echo '<h1>'.$node[elementID].'</h1>';
}

I hope this helps.

于 2012-06-28T16:10:26.467 回答
0

Strange. This, however, works.

$textNode = $xml->xpath("//*[name() = 'RichText']");
于 2012-06-28T16:12:09.890 回答