ivobenedito Posted March 15, 2006 Share Posted March 15, 2006 Hi,I'm creating a new XML Document in php using PHP DOM and when i use the method saveXML() i just get a blank string instead of a string with the content of the xmlDoc that i created. Here is the code :[code]<?php$doc = new DOMDocument('1.0');$doc->formatOutput = true;$root = $doc->createElement('book');$root = $doc->appendChild($root);$title = $doc->createElement('title');$title = $root->appendChild($title);$text = $doc->createTextNode('This is the title');$text = $title->appendChild($text);echo "Retrieving all the document:\n";echo $doc->saveXML() . "\n";echo "Retrieving only the title part:\n";echo $doc->saveXML($title);?>[/code]Does anyone know what may be the problm ?? It just doesn't work with or without argument's in saveXML method and doesn't output any compilation error. I just get a blank browser page ;( !! Link to comment https://forums.phpfreaks.com/topic/5051-php-dom-dom-savexml-prblm/ Share on other sites More sharing options...
ober Posted March 15, 2006 Share Posted March 15, 2006 Odd. I know you got that code from the manual, so I tried the same code myself and got the same results. I'll look into it some more. Link to comment https://forums.phpfreaks.com/topic/5051-php-dom-dom-savexml-prblm/#findComment-17889 Share on other sites More sharing options...
redarrow Posted March 15, 2006 Share Posted March 15, 2006 I found this one for you hope it works, I looked around the net and the above code is all over the net but dosent seem to work but try this good luck.[code] <?php $books = array(); $books [] = array( 'title' => 'PHP Hacks', 'author' => 'Jack Herrington', 'publisher' => "O'Reilly" ); $books [] = array( 'title' => 'Podcasting Hacks', 'author' => 'Jack Herrington', 'publisher' => "O'Reilly" ); $doc = new DOMDocument(); $doc->formatOutput = true; $r = $doc->createElement( "books" ); $doc->appendChild( $r ); foreach( $books as $book ) { $b = $doc->createElement( "book" ); $author = $doc->createElement( "author" ); $author->appendChild( $doc->createTextNode( $book['author'] ) ); $b->appendChild( $author ); $title = $doc->createElement( "title" ); $title->appendChild( $doc->createTextNode( $book['title'] ) ); $b->appendChild( $title ); $publisher = $doc->createElement( "publisher" ); $publisher->appendChild( $doc->createTextNode( $book['publisher'] ) ); $b->appendChild( $publisher ); $r->appendChild( $b ); } echo $doc->saveXML(); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/5051-php-dom-dom-savexml-prblm/#findComment-17903 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.