Xpath attribute value check with a variable passed using PHP

simcoumidio

New Member
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:\[code\]$obj= $xml->xpath('/document/item[@id = "a12sd"]');\[/code\]This does not work, because I need to pass the value via a variable to check with the attribute value\[code\]$checkID = "a12sd";$obj= $xml->xpath('/document/item[@id = $checkID]');\[/code\]Any suggestions how I can rectify this problem.EDIT:XML File:\[code\]<?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>\[/code\]PHP Code:\[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");\[/code\]Thanks
 
Back
Top