Creating XML DOM issue
Posted: Wed Jan 15, 2003 12:22 am
Ok,
PHP 4.3.0...
Here's one for the XML/DOM guru's. I have the following code segment:
$doc = domxml_new_doc("1.0");
$root = $doc->create_element('users');
$doc->append_child($root);
$node = $doc->create_element('uid');
$root->append_child($node);
$node->append_child($doc->create_text_node('this is some text'));
print("<pre>");
print_r( $doc);
$doc2 = xmltree($doc->html_dump_mem());
print_r( $doc2);
print $doc->children[0]->children[0]->children[0]->content;
print $doc2->children[0]->children[0]->children[0]->content;
print( "</pre><br><br><br>" );
That creates the structure that I am looking for. But when I run the first print_r() my XML layout is not complete. It's like I cannot access any of teh elements until after I export them and reimport them. The call to print $doc->children[0]->children[0]->children[0]->content; should print "this is some text" but I get nothing. I verifu that the data is correct by running the second call on $doc2.
Is there a reason that the DOM Object is not rendered while building it?
Shouldn't we be able to render an object even through we are still adding to it? Is this a feature or bug? Am I missing something (like commit current changes or something)?
The primary reason that I need this functionality is that as we build a few master nodes we need to itterate through the existing nodes to verify some items.
Thanks,
Gary Smith
PHP 4.3.0...
Here's one for the XML/DOM guru's. I have the following code segment:
$doc = domxml_new_doc("1.0");
$root = $doc->create_element('users');
$doc->append_child($root);
$node = $doc->create_element('uid');
$root->append_child($node);
$node->append_child($doc->create_text_node('this is some text'));
print("<pre>");
print_r( $doc);
$doc2 = xmltree($doc->html_dump_mem());
print_r( $doc2);
print $doc->children[0]->children[0]->children[0]->content;
print $doc2->children[0]->children[0]->children[0]->content;
print( "</pre><br><br><br>" );
That creates the structure that I am looking for. But when I run the first print_r() my XML layout is not complete. It's like I cannot access any of teh elements until after I export them and reimport them. The call to print $doc->children[0]->children[0]->children[0]->content; should print "this is some text" but I get nothing. I verifu that the data is correct by running the second call on $doc2.
Is there a reason that the DOM Object is not rendered while building it?
Shouldn't we be able to render an object even through we are still adding to it? Is this a feature or bug? Am I missing something (like commit current changes or something)?
The primary reason that I need this functionality is that as we build a few master nodes we need to itterate through the existing nodes to verify some items.
Thanks,
Gary Smith