||07-12-2011 12:52 AM
How to traverse through the XML nodes?
Dear friends of linuxquestions.org;
I'm struggling with a very irritating problem:
I have a xml file and I read it within a php file with XML dom.
This is the node structure of my xml file :
Here are the php code of mine:
$in_name = $_POST["name"];
$in_surname = $_POST["surname"];
$in_department = $_POST["department"];
$doc = new DOMDocument();
$xPath = new DOMXPath($doc);
if($in_name != '')
$nodeList = $xPath->query('//User/name');
$phase = trim(($in_name));
$length_of_phase = strlen($phase);
foreach($nodeList as $node)
if( strncasecmp( trim($node->nodeValue),$phase,$length_of_phase) == 0)
$parent_nodes = $node->parentNode;
//Here is the point
for($i = 1; $i <= 4; $i++)
In the comment line, I've got the parent node of the current node. Parent node is "User" node. I would like to obtain the children of this parent node, say "name","surname " etc. How can I do this? Is there any function such as : "$parent_nodes->bringChildren('name')". I could not find it.
Thanks in advance.