php - Xpath: Use a variable in an Xpath string -


i new xpath sorry if silly question, it's been driving me nuts. have xml file looks this:

<itemlist> <item id="01">     <color>red</color>     <type>box</type>     <material>metal</material> </item> <item id="02">     <color>blue</color>     <type>cone</type>     <material>wood</material> </item>  </itemlist> 

when run following, error "notice: trying property of non-object "

$id = $_get['code'];  $doc = new domdocument; $doc->validateonparse = true; $doc->load('file.xml');  $xpath = new domxpath($doc);  $color = $xpath->query("//itemlist/item[@id='" . $id . "']/color");  echo $color->item(0)->nodevalue; 

as far can tell, syntax wrong i'm trying insert variable. tried '" + $id + "' same error. appreciated.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -