2012-03-21 14 views
0

私はいくつかの製品のデータを取得しようとしており、各製品の属性をリストしています。私は、属性ID = "259"から同じ属性で終わっています。誰も私の問題を解決できますか?XML属性を取得するにはどうすればよいですか?

$xml=simplexml_load_file($xml_file); 
foreach($xml->AttributeValue[0]->attributes() as $key => $value) { 
    echo $a,'="',$b,"\"\n"; 
} 

はまた与えてみ XML例

<AttributeValue id="258888"> 
<name>HON</name> 
</AttributeValue> 
<AttributeValue id="276682"> 
<name>Office Star</name> 
</AttributeValue> 

<Attribute id="296935"> 
<name>Stores</name> 
<AttributeValues> 
<AttributeValue id="18893"> 
<name>Test</name> 
</AttributeValue> 
</AttributeValues> 
</Attribute> 
</RelatedAttributes> 

    foreach($xml->RelatedAttributes->Attribute as $attribute){ 
echo $attribute->name; //main Attribute Name 

foreach($xml->RelatedAttributes->Attribute->AttributeValues->AttributeValue as $attribute_values){ 
echo $attribute_values->name; //subtopic for main Attribute 

}} 

答えて

0

てみ

$attr = $xml->AttributeValue[0]->attributes(); 
echo $attr['id']; 
関連する問題