I am trying to perform a simple xpath lookup using an XML file from an HTTP POST. I've been pulling my hair out, as this should work!! Everything I've found thus far is a result of the namespace, but I have no namespace in this XML.
<?xml version="1.0" encoding="UTF-8"?> <foo> <bar> <name>Frank</name> </bar> </foo> Here is the simple code I'm using.
$xml = new SimpleXMLElement(file_get_contents("php://input"); print_r($xml->xpath("//FOO/bar/name")); This gives me an empty array!
Array ( [0] => SimpleXMLElement Object ( ) ) If I just do print_r($xml->xpath("//foo")); I see it has the data, but as soon as I try to get the value of name, I get nothing. :(
Array ( [0] => SimpleXMLElement Object ( [bar] => SimpleXMLElement Object ( [name] => Frank ) ) ) What is the deal?? Thank you!!
FOO !== foo. Thought I was cleaning up code with edit. CaSe sensitivity was actually your issue. Suggest close as a 'typo' question. stackoverflow.com/posts/49436522/revisions$xml->xpath("//foo/bar/name")[0]->__toString()as far back as 5.4. That doesn't address the underlying issue of what you're trying to do for your current version though.