im looking for a much easier way to iterate over a nodelist containing variable elements so i dont have to use manual assignment
e.g.
$nodeList = $xpath->query('//product');
$nodeLength = $nodeList->length;
foreach ($nodeList as $nodes)
{
$hid = $nodes->getElementsByTagName('id')->item(0)->nodeValue;
$oid = $nodes->getElementsByTagName('orderid')->item(0)->nodeValue;
$pid = $nodes->getElementsByTagName('pid')->item(0)->nodeValue;
$rdate = $nodes->getElementsByTagName('regdate')->item(0)->nodeValue;
$status = $nodes->getElementsByTagName('status')->item(0)->nodeValue;
$xml .= '<product>';
$xml .= '<hid>'.$hid.'</hid>';
$xml .= '<oid>'.$oid.'</oid>';
$xml .= '<pid>'.$pid.'</pid>';
$xml .= '<rdate>'.$rdate.'</rdate>';
$xml .= '<status>'.$status.'</status>';
$xml .= '</product>';
}
is there a way I can use nodeName and nodeValue here to just do a one liner loop?
i've tried this...
$xml .= '<product>';
foreach ($nodes as $node)
{
$xml .= '<'.$node->nodeName.'>'.$node->nodeValue.'</'.$node->nodeName.'>';
}
$xml .= '</product>';
but i get a ton of empty brackets along with other issues if i dont cdata the nodeValue.. I also get stuff like #text before the nodeNames
Manual assignment, besides being tedious, is almost impossible b/c while there are a handle full of similar tags between loops, there are numerous others that each structure doesnt share that I need
any assistance would be greatly appreciated