This article mainly introduces the xml format data of books implemented by php based on dom, and analyzes the related operation skills for converting php array to xml format data in the form of examples, for more information about how to convert xml data from php arrays, see this article, for more information, see
This document describes the xml format of books implemented by php based on dom. We will share this with you for your reference. The details are as follows:
'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();?>
The running result is as follows:
Jack Herrington
PHP Hacks
O'Reilly
Jack Herrington
Podcasting Hacks
O'Reilly