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

dom_import_simplexml

(PHP 5, PHP 7)

dom_import_simplexml - 从SimpleXMLElement对象中获取DOMElement对象

描述

代码语言:javascript
复制
DOMElement dom_import_simplexml ( SimpleXMLElement $node )

该函数接受nodeSimpleXML的节点并将其放入DOMElement节点。这个新对象可以用作本地DOMElement节点。

参数

node

SimpleXMLElement节点。

返回值

添加DOMElement节点或FALSE发生任何错误。

例子

示例#1使用dom_import_simplexml()将SimpleXML导入到DOM中

代码语言:javascript
复制
<?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();

?>

扫码关注腾讯云开发者

领取腾讯云代金券