1

I'm trying to extract data property[value] from xml, the $xml->xpath("/products") shows:

 [categories] => SimpleXMLElement Object ( [category] => Zapas ) 

[properties] => SimpleXMLElement Object ( 
[property] => 
    Array ( 
    [0] => SimpleXMLElement Object ( [@attributes] => 
        Array ( 
            [name] => VAL) 
            [value] => 1111111 ) 
    [1] => SimpleXMLElement Object ( [@attributes] => 
        Array ( 
            [name] => manufacturer ) 
            [value] => Nike) 
    [2] => SimpleXMLElement Object ( [@attributes] => 
        Array ( 
            [name] => condition ) 
            [value] => new ) 
    [3] => SimpleXMLElement Object ( [@attributes] => 
        Array ( 
            [name] => deliveryCosts ) 
            [value] => 0.00 ) 
    [4] => SimpleXMLElement Object ( [@attributes] => 
        Array ( 
            [name] => stock ) 
            [value] => in stock ) 
    ) )

I'm using next code for extracting xml values:

$xml =  simplexml_load_file("http://productType=2",'SimpleXMLElement'); 
foreach($xml->product as $file){ 
$file->categories->category; 
$file->properties????
}

The problem: I can't extract e.g Nike from:

[properties] => SimpleXMLElement Object ( 
    [property] => 
      Array ( 
         [0] => SimpleXMLElement Object ( [@attributes] => 
              Array (
                 [1] => SimpleXMLElement Object ( [@attributes] => 
                      Array ( 
                            [name] => manufacturer ) 
                            [value] => Nike)...

using

$brand= (string)$file->properties->property[1]->attributes() 

I got manufacturer data (name), but

$brand= (string)$file->properties->property[1]->attributes()->value

doesn't works for getting Nike (value)

How could I get property[value] data? Thanks in advance

Phil
  • 11
  • 1
  • Try `$file->properties->property[1]->attributes[1]->attributes['value']` – al'ein Sep 01 '15 at 11:34
  • thanks for answering, I tried but doesn't works $brand=$file->properties->property[1]->attributes[1]->attributes['value']; I keep trying – Phil Sep 01 '15 at 11:57
  • Well I think [it might help you](http://stackoverflow.com/questions/1652128/accessing-attribute-from-simplexm) then. – al'ein Sep 01 '15 at 12:32
  • 1
    I got it, the right way is : $brand= $file->properties->property[1]->{'value'}; @AedixRhinedale tahnks for your help – Phil Sep 01 '15 at 17:06
  • great! Answer your own question, then. It might be useful for somebody PLUS you gain some rep points :) – al'ein Sep 01 '15 at 18:21

0 Answers0