dom_import_simplexml
(PHP 5, PHP 7)
dom_import_simplexml - 从SimpleXMLElement对象中获取DOMElement对象
描述
DOMElement dom_import_simplexml ( SimpleXMLElement $node )
该函数接受node
类SimpleXML的节点并将其放入DOMElement节点。这个新对象可以用作本地DOMElement节点。
参数
node
SimpleXMLElement节点。
返回值
添加DOMElement节点或FALSE
发生任何错误。
例子
示例#1使用dom_import_simplexml()将SimpleXML导入到DOM中
<?php
$sxe = simplexml_load_string('<books><book><title>blah</title></book></books>');
if ($sxe === false) {
echo 'Error while parsing the document';
exit;
}
$dom_sxe = dom_import_simplexml($sxe);
if (!$dom_sxe) {
echo 'Error while converting XML';
exit;
}
$dom = new DOMDocument('1.0');
$dom_sxe = $dom->importNode($dom_sxe, true);
$dom_sxe = $dom->appendChild($dom_sxe);
echo $dom->saveXML();
?>
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com