php - SimpleXML multidimensional nodes -


i have xml this:

<properties>   <property>name</property><value>john</value>   <property>surname</property><value>wayne</value>   <property>age</property><value>33</value>   <property>blaaa</property><value>blaa</value> </properties> 

i have parse , used this:

$xle = simplexml_load_file('xml.xml'); foreach ($xle->properties $properties) {     foreach ($properties->property $property) {         echo $property, "<br />\n";     }     foreach ($properties->value $value) {         echo $value, "<br />\n";     } } 

i came far, need like

"property = value" "name = john"

my code outputs :

name surname age blaa john wayne 33 blaa 

each value following sibling property element. can express xpath quite easily:

following-sibling::value[1] 

will give <value> element if <property> element context-node.

getting context-node simplexml rather straight forward, here example php code:

$properties = simplexml_load_file('xml.xml');  foreach($properties->property $property) {     list($value) = $property->xpath('following-sibling::value[1]');     echo $property, " = ", $value, "\n"; } 

the output example xml is:

name = john surname = wayne age = 33 blaaa = blaa 

online demo

this looks similar properties file (plist) know of related q&a memory, it's maybe interesting you:


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -