I need help from selecting data from XML. I can't seem to figure out the way xpath works with specific data selecting. Here is my XML:
<?xml version="1.0"?>
<a>
<b>
<c>Value 1</c>
<d>Value 2</d>
</b>
<b>
<c>Value 3</c>
<d>Value 4</d>
</b>
And PHP code i'm trying to use would be:
<?php
$xml = simplexml_load_file("xml.xml");
$result = $xml->xpath('b/c | b/d');
foreach ($result as $val){
echo $val['c'] . $val['d'] . "<br>;
}
If i echo $val, i get all values, however, i want to separate it so i have $val['c'] and $val['d'], like when selecting specific data from MySQL table. Thank you in advance
No comments:
Post a Comment