2012-03-21 3 views
0

나는 여러 제품에 대한 데이터를 가져 와서 각 제품의 속성을 나열하려고합니다. 나는 Attribute 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']; 
관련 문제