I have a function which is trying to get text from XML
using XPath
query.The function reads:
function getInterviewText($id) {
$sxe = simplexml_load_file("./interview2.xml");
foreach($sxe->xpath('//interview') as $item) {
$row = simplexml_load_string($item->asXML());
$v = $row->xpath('//interview-id[.="$id"]');
if($v[0]) {
echo '<interview-text>'.$item->INTERVIEW-TEXT.'</interview-text>'
}
}
}
The XML File reads:
<?xml version="1.0"?>
<ROOT>
<interview>
<interview-id>1</interview-id>
<INTERVIEW-TEXT>
Test1
</INTERVIEW-TEXT>
</interview>
<interview>
<interview-id>2</interview-id>
<INTERVIEW-TEXT>
Test2
</INTERVIEW-TEXT>
</interview>
</ROOT>
However, the function is not returning anything, when I am trying to call it with id=1 or 2. Any help is greatly appreciated.
Thanks