首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

PHP 透过DOM方式创建一个book.xml文件

2013-03-10 
PHP 通过DOM方式创建一个book.xml文件?php$doc new DOMDocument(1.0,utf-8)$bookshelf $doc -c

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');
?>

热点排行