corillo181 Posted August 24, 2007 Share Posted August 24, 2007 hey i want to know wha tis the best way to write and add to a xml file? if i have a xml page with <music> <artistID>#</artistID> <artistName>name</artistName> <pictures> <picture>url</picture> <picture>url</picture> <picture>url</picture> </pictures> </music> gaol 1. to add new artist Link to comment https://forums.phpfreaks.com/topic/66555-writing-to-xml/ Share on other sites More sharing options...
corillo181 Posted August 24, 2007 Author Share Posted August 24, 2007 what happen no answer? Link to comment https://forums.phpfreaks.com/topic/66555-writing-to-xml/#findComment-333389 Share on other sites More sharing options...
$username Posted August 24, 2007 Share Posted August 24, 2007 Is this a new xml file that you are creating? I think that you could use XML with the DOM... But I do not know to much about this yet. I have been working on this a little <?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(); ?> Link to comment https://forums.phpfreaks.com/topic/66555-writing-to-xml/#findComment-333406 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.