just a quick question, was trying different ways to accomplish this, but ended with no success. I am trying to check attribute value using xpath and if the attribute value matches, I change the parameters for that tag in xml.
This works:
$obj= $xml->xpath('/document/item[@id = "a12sd"]');
This does not work, because I need to pass the value via a variable to check with the attribute value
$checkID = "a12sd";
$obj= $xml->xpath('/document/item[@id = $checkID]');
Any suggestions how I can rectify this problem.
EDIT:
XML File:
<?xml version="1.0" encoding="ISO-8859-1"?>
<document>
<item id="a12sd">
<name>James</name>
<pdf>0023.pdf</pdf>
</item>
<item id="rdf23">
<name>Alex</name>
<pdf>0178.pdf</pdf>
</item>
<item id="2we34">
<name>Tom</name>
<pdf>0886.pdf</pdf>
</item>
<item id="123de">
<name>Robby</name>
<pdf>1239.pdf</pdf>
</item>
</document>
PHP Code:
$id = "a12sd";
$xml = simplexml_load_file('items.xml');
$who_is_who = $xml->xpath('/document/item[@id = "a12sd"]');
$who_is_who[0]->name = "Arnold";
$xml->asXml("items.xml");
Thanks
[@id = "$checkID"]$obj= $xml->xpath('/document/item[@id="'.$checkID.'"]');