Hi all,
I've tried to figure it out by using domxml :
$root = $doc->document_element();
handleElement($root);
function handleElement($element)
{
if ($element->node_type() == XML_ELEMENT_NODE)
{
echo "Found opening tag of element: " .$element->node_name() . "\n";
$children = $element->children();
for ($i=0;$i<sizeof($children);$i++)
{
if ($children[$i]->node_type() == XML_ELEMENT_NODE)
{
echo "Found opening tag of element: " .$children[$i]->node_name() . "\n";
$text = $children[$i]->children();
$cdata = $text[0]->content;
echo "Found PCDATA: " . $cdata . "\n";
$child = $children[$i]->children();
foreach ($child as $childnode)
{ handleElement($childnode);
}
echo "Found closing tag of element: " .$children[$i]->node_name() . "\n";
}
else if ($children[$i]->node_type() == XML_CDATA_SECTION_NODE)
{
echo "Found CDATA Section with content = " .$children[$i]->node_value() . "\n";
}
else if ($children[$i]->node_type() == XML_ATTRIBUTE_NODE)
{
echo "Found attribute: " .$children[$i]->node_name() . " = " .$children[$i]->node_value(). "\n";
}
else if ($children[$i]->node_type() == XML_PI_NODE)
{
echo "Found Processing Instruction node: Target = " .$children[$i]->node_name(). " with code = " .$children[$i]->node_value()
."\n";
}
else if ($children[$i]->node_type() == XML_ENTITY_REF_NODE)
{
echo "Found Entity Reference:" .$children[$i]->node_name(). "\n";
}
}
echo "Found closing tag of element: " .$element->node_name(). "\n";
}
}
But i still can't get the attributes of each node and the result still wrong :
Found opening tag of element: invoice
Found opening tag of element: customer
Found PCDATA:
Found opening tag of element: name
Found closing tag of element: name (-->why name element doesn't print any content??)
Found opening tag of element: address
Found opening tag of element: line
Found PCDATA: abc street
Found closing tag of element: line
Found opening tag of element: line
Found PCDATA:California
Found closing tag of element: line
Found opening tag of element: line
Found PCDATA: USA
Found closing tag of element: line
Found closing tag of element: address
Found closing tag of element: customer
Found CDATA Section with content =
John doe is a loyal customer
Found opening tag of element: date
Found PCDATA: 2004-05-07
Found closing tag of element: date
Found opening tag of element: reference
Found PCDATA: 123-344-3
Found closing tag of element: reference
Found opening tag of element: items
Found PCDATA:
Found opening tag of element: item
...
Can someone help me please??I try and i try to fix it.maybe i was wrong to call the function itself for the child element.But i don't know what's wrong..
Regards,
Christy