savexml php,PHP DOMDocument saveXML()用法及代码示例

DOMDocument::saveXML()函数是PHP中的一个内置函数,用于从DOM表示形式创建XML文档。从头开始构建新的dom文档后使用此功能。

用法:

string DOMDocument::saveXML( DOMNode $node, int $options = 0 )

参数:该函数接受上述和以下描述的两个参数:

$node:此参数仅用于没有XML声明的特定节点的输出,而不是整个文档的输出。

$options:此参数添加其他选项。当前,此参数仅支持LIBXML_NOEMPTYTAG。

返回值:如果成功,此函数返回XML文档;如果失败,则返回FALSE。

以下示例程序旨在说明PHP中的DOMDocument::saveXML()函数:

示例1:

// Create a new DOMDocument

$domDocument = new DOMDocument('1.0', 'iso-8859-1');

// Use createTextNode() function to create a text node

$domTN = $domDocument->createTextNode('GeeksforGeeks');

// Append element to the document

$domDocument->appendChild($domTN);

// Use saveXML() function to save the XML document

echo $domDocument->saveXML();

?>

输出:

GeeksforGeeks

示例2:

// Create a new DOMDocument

$domDocument = new DOMDocument('1.0', 'iso-8859-1');

// Use createElement() function to create an element node

$domElement = $domDocument->createElement('organization',

'GeeksforGeeks');

// Append element to the document

$domDocument->appendChild($domElement);

// Use saveXML() function to create a XML document

echo $domDocument->saveXML();

?>

输出:

GeeksforGeeks

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值