jobo: SimpleXML Xpath Attributwert

Beitrag lesen

Hallo,

  
  
<?php  
  
$xml_string=  
'<?xml version="1.0"?>  
<wurzel>  
<CarInfo Code="1" Quantity="10"/>  
<CarInfo Code="CodeWhereQuantityEq22" Quantity="22">  
<abc>somevalueInAbc</abc>  
</CarInfo>  
<CarInfo Code="3" Quantity="23"/>  
<CarInfo Code="4" Quantity="42"/>  
<CarInfo Code="5" Quantity="33"/>  
<CarInfo Code="6" Quantity="87"/>  
</wurzel>';  
//	echo $xml_string;  
	$simple_xml = simplexml_load_string($xml_string);  
//	var_dump($simple_xml);  
	$query_string="//CarInfo[@Quantity=22]";  
	$node_list = $simple_xml->xpath($query_string);  
	var_dump($node_list);  
	echo $node_list[0]["Code"]."  
";  
	echo $node_list[0]->abc;  

Gruß

jobo