kwindo Posted March 1, 2011 Share Posted March 1, 2011 I'm having a slight problem selecting an item based on the value of one of it's child nodes. Let's say I need to find the value from the "id" value in the item that has a value "Fables" in it's "name" node.Example xml: <?xml version="1.0" encoding="UTF-8"?><results> <game> <id>01</id> <name>Final Fantasy Fables</name> </game> <game> <id>02</id> <name>Fantasy Fables</name> </game> <game> <id>03</id> <name>Fables</name> </game> <game> <id>04</id> <name>Something Totally Different</name> </game></results> I have this PHP: $parent = '//results/game/name[contains(., "Fables")]'; // Xpath to parent$resultsb = $xml->xpath($parent);foreach ($results as $titleElement) { $game = simplexml_import_dom(dom_import_simplexml($titleElement)->parentNode); echo $game -> name; } However this returns:Final Fantasy FablesFantasy FablesFablesSo its returning all games of which the "name" node contains "Fables". Is there a similar way to find the game of which the "name" node is identical to "Fables"? I tried stuff with "deep-equal" in the Xpath to parent but until now this gives me no results.Thanks! Link to comment Share on other sites More sharing options...
jeffman Posted March 1, 2011 Share Posted March 1, 2011 Try this: '//results/game/name[. = "Fables"]' It's a pretty common pattern. Just to be sure, I tested it using DOMDocument and DOMXpath, and it works fine. I don't know why it wouldn't work in your technique. Link to comment Share on other sites More sharing options...
kwindo Posted March 2, 2011 Author Share Posted March 2, 2011 I tried that and it does exactly what it's aspected to do.Thanks very mush! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.