xpath help
Posted: Mon Dec 18, 2006 9:09 am
I'm trying to use xpath to pick out a node name from an xml input string. A sample of the xml I'll be parsing:
This code returns:
I don't think I'm doing the node navigation correctly, but this is how I interpreted the implementation from the xpath tutorials I've read. Can anyone give advice as to where I'm going wrong? Thanks very much.
I need to pick out the child node of "request." That node name, which is "send" in this example, can be one of four or five different names, like "groups," "join," etc. I've tried using this code to pick out the "send" node name:<?xml version="1.0" encoding="UTF-8"?><request account="xxxxx" password="xxxxxx"><send param1="test" param2="ececececec" /></request>
Code: Select all
function getCommandReq($req)
{
$result = $req->xpath('/request/*');
$reqCommand = (string) key($result[0]);
echo '***REQUEST COMMAND: ', $reqCommand, '***';
}Code: Select all
***REQUEST COMMAND: @attributes***