Is it that PHP will automatically strips off the tags of an xml doc?
I'm on win2k platform with the latest php and apache, and use their recommended ini and conf file with a slight modification, so will it be the problem of the config files?
or it's the standard behavior of PHP treating xml files?because i do readfile($xmlfilename), the results the same, prints only the text(text nodes), and without the tags
below is the code :
<?php
make an example xml document to play with
$xmlstr = "<" . "?" . "xml version=\"1.0\"" . "?" . ">";
$xmlstr .=
"
<employee>
<name>Matt</name>
<position type=\"contract\">Web Guy</position>
</employee>
";
this prints out only the text, instead of the whole doc
print $xmlstr;
and the domxml_version() too, have no responding at all
print domxml_version();
load xml data ($doc becomes an instance of
the DomDocument object)
$doc = domxml_new_mem($xmlstr);
get root node "employee"
$employee = $doc->document_element();
get employee's children ("name","position")
$nodes = $employee->child_nodes();
let's play with the "position" node
so we must iterate through employee's
children in search of it
while ($node = array_shift($nodes))
{
if ($node->node_name() == "position")
{
$position = $node;
break;
}
}
get position's type attribute
$type = (array_shift($position->attributes()))->node_value();
get the text enclosed by the position tag
shift the first element off of position's children
$text_node = array_shift($position->child_nodes());
access the content property of the text node
$text = $text_node->node_value();
echo out the position and type
echo "position: $text<BR>";
echo "type: $type";
?>
Thanks in advance