您的位置:首页 > 编程语言 > PHP开发

php如何通过dom创建xml

2013-03-13 19:16 471 查看
PHP 通过DOM方式创建一个book.xml文件

<?php

header("Content-Type:text/html;charset:utf-8");

$doc=new DOMDocument();

$bookshlf=$doc->createElement('bookshlf');

$doc->appendChild($bookshlf);

$book=$doc->createElement('book');

$title=$doc->createElement('title');

$title->nodeValue='雪山飞狐';

$author=$doc->createElement('author');

$author->nodeValue='金庸';

$book->appendChild($title);

$book->appendChild($author);

$bookshlf->appendChild($book);

$doc->formatOutput=true;

$doc->save('book.xml');

?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: