PHP 通过DOM方式创建一个book.xml文件
<?php
$doc = new DOMDocument('1.0','utf-8');
$bookshelf = $doc ->createElement('bookshelf');
$doc ->appendChild($bookshelf);
$book = $doc ->createElement('book');
$bookshelf ->appendChild($book);
$title = $doc ->createElement('title');
$title ->nodeValue = '笑傲江湖';
$book ->appendChild($title);
$author = $doc ->createElement('author');
$author ->nodeValue = '金庸';
$book ->appendChild($author);
$book = $doc ->createElement('book');
$bookshelf ->appendChild($book);
$title = $doc ->createElement('title');
$title ->nodeValue = '天龙八部';
$book ->appendChild($title);
$author = $doc ->createElement('author');
$author ->nodeValue = '金庸';
$book ->appendChild($author);
$book = $doc ->createElement('book');
$bookshelf ->appendChild($book);
$title = $doc ->createElement('title');
$title ->nodeValue = '神雕侠侣';
$book ->appendChild($title);
$author = $doc ->createElement('author');
$author ->nodeValue = '金庸';
$book ->appendChild($author);
$book = $doc ->createElement('book');
$bookshelf ->appendChild($book);
$title = $doc ->createElement('title');
$title ->nodeValue = '陆小凤传奇';
$book ->appendChild($title);
$author = $doc ->createElement('author');
$author ->nodeValue = '古龙';
$book ->appendChild($author);
$doc ->save('book.xml');
?>