My record.xml looks like :
<record>
<name>john</name>
<gender>male</gender>
<subject>mathematics, english, science</subject>
</record>
<record>
<name>jamie</name>
<gender>female</gender>
<subject>mathematics, science</subject>
</record>
<record>
<name>jamie</name>
<gender>female</gender>
<subject>social-science, english</subject>
</record>
I want to write a xpath query which will return record node containing one or more given subjects.
For Example :
If want to get record of student with subject mathematics and science
then second record should be returned i.e.
<record>
<name>jamie</name>
<gender>female</gender>
<subject>mathematics, science</subject>
</record>
This is what i did till now :
<?php
$xmldoc = new DOMDocument();
$xmldoc->load('record.xml');
$xpathvar = new Domxpath($xmldoc);
$res = $xpathvar->query('//record/subject[. = "science"]');
foreach($res as $data){
echo $data->textContent.'<br>';
}
?>
I want to Achieve Result Something Like this :
<?php
$xmldoc = new DOMDocument();
$xmldoc->load('record.xml');
$xpathvar = new Domxpath($xmldoc);
$res = $xpathvar->query('//record/subject[. = "science" and mathematics]');
foreach($res as $data){
echo $data->textContent.'<br>';
}
?>