Example of book xml format data implemented by php based on dom_php skills

PHP中文网
Release: 2016-05-16 19:13:20
Original
1352 people have browsed it

This article mainly introduces the book XML format data implemented by PHP based on DOM, and analyzes the related operation skills of PHP array to convert XML format data in the form of examples. Friends in need can refer to

The examples in this article are described The book xml format data implemented by PHP based on DOM. Share it with everyone for your reference, the details are as follows:


<?php
 $books = array();
 $books [] = array(
 &#39;title&#39; => &#39;PHP Hacks&#39;,
 &#39;author&#39; => &#39;Jack Herrington&#39;,
 &#39;publisher&#39; => "O&#39;Reilly"
 );
 $books [] = array(
 &#39;title&#39; => &#39;Podcasting Hacks&#39;,
 &#39;author&#39; => &#39;Jack Herrington&#39;,
 &#39;publisher&#39; => "O&#39;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[&#39;author&#39;] )
 );
 $b->appendChild( $author );
 $title = $doc->createElement( "title" );
 $title->appendChild(
 $doc->createTextNode( $book[&#39;title&#39;] )
 );
 $b->appendChild( $title );
 $publisher = $doc->createElement( "publisher" );
 $publisher->appendChild(
 $doc->createTextNode( $book[&#39;publisher&#39;] )
 );
 $b->appendChild( $publisher );
 $r->appendChild( $b );
 }
 echo $doc->saveXML();
?>
Copy after login


The running results are as follows:


<?xml version="1.0"?>
<books>
 <book>
  <author>Jack Herrington</author>
  <title>PHP Hacks</title>
  <publisher>O&#39;Reilly</publisher>
 </book>
 <book>
  <author>Jack Herrington</author>
  <title>Podcasting Hacks</title>
  <publisher>O&#39;Reilly</publisher>
 </book>
</books>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!