简单入门级php 生成xml文档代码

作者:袖梨 2022-06-24

$doc = new domdocument('1.0');
// we want a nice output
$doc->formatoutput = true;

 代码如下 复制代码

$root = $doc->createelement('book');
$root = $doc->appendchild($root);

$title = $doc->createelement('title');$title = $root->appendchild($title);

$text = $doc->createtextnode('this is the title');
$text = $title->appendchild($text);

echo "retrieving all the document: ";
echo $doc->savexml() . " ";

echo "retrieving only the title part: ";
echo $doc->savexml($title);

相关文章

精彩推荐