Hello.

I create xml file with structure

<?xml version="1.0" encoding="utf-8"?> <parent> <son>Tolya</son> <big>Sash ...... <year>1999</year> ..... <fu> future <date>dates</date> </fu> </big> </parent> 

Now there is a php file

 $xml=simplexml_load_file('info.xml'); 

I want to access the property values ​​of the $ xml object. You can access the son, but I don’t know how to year (it can be nested in a couple of elements) if the file structure is not known . Help with the function of traversing all properties of the object. I tried to create such a function to bypass all the elements.

 function recurse($obj){ foreach($obj as $k=>$v){ if(is_object($k)) {recurse($k);} else{ echo $k; } } } recurse($xml); 

but failed.

    1 answer 1

     $xml = new SimpleXMLElement('info.xml'); foreach ($xml->parent as $val) { echo $val->son.'<br>'; echo $val->big->year.'<br>'; } 
    • I don’t know where the Year is. Maybe it is invested in a couple more elements. How can I proceed? - zloctb
    • one
      Look for the function maybe php.net/manual/en/book.simplexml.php Either through a regular expression! - Epexa