首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

DOMDocumentFragment::appendXML

(PHP 5 >= 5.1.0, PHP 7)

DOMDocumentFragment :: appendXML - 附加原始XML数据

描述

代码语言:javascript
复制
public bool DOMDocumentFragment::appendXML ( string $data )

将原始XML数据追加到DOMDocumentFragment。

这种方法不是DOM标准的一部分。它被创建为在DOMDocument中附加XML DocumentFragment的更简单的方法。

如果你想遵守标准,你将不得不用一个虚拟根创建一个临时的DOMDocument,然后遍历XML数据根的子节点来追加它们。

参数

data

要附加的XML。

返回值

成功时返回TRUE或失败时返回FALSE

例子

示例#1将XML数据附加到文档

代码语言:javascript
复制
<?php
$doc?=?new?DOMDocument();
$doc->loadXML("<root/>");
$f?=?$doc->createDocumentFragment();
$f->appendXML("<foo>text</foo><bar>text2</bar>");
$doc->documentElement->appendChild($f);
echo?$doc->saveXML();?
?>

上面的例子将输出:

代码语言:javascript
复制
<?xml version="1.0"?>
<root><foo>text</foo><bar>text2</bar></root>

← DOMDocumentFragment

DOMDocumentType →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com