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 Quote 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? Quote 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/66555-writing-to-xml/#findComment-333406 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.