savexml php,PHP DOMDocument saveXML()用法及代码示例
DOMDocument::saveXML()函數(shù)是PHP中的一個(gè)內(nèi)置函數(shù),用于從DOM表示形式創(chuàng)建XML文檔。從頭開(kāi)始構(gòu)建新的dom文檔后使用此功能。
用法:
string DOMDocument::saveXML( DOMNode $node, int $options = 0 )
參數(shù):該函數(shù)接受上述和以下描述的兩個(gè)參數(shù):
$node:此參數(shù)僅用于沒(méi)有XML聲明的特定節(jié)點(diǎn)的輸出,而不是整個(gè)文檔的輸出。
$options:此參數(shù)添加其他選項(xiàng)。當(dāng)前,此參數(shù)僅支持LIBXML_NOEMPTYTAG。
返回值:如果成功,此函數(shù)返回XML文檔;如果失敗,則返回FALSE。
以下示例程序旨在說(shuō)明PHP中的DOMDocument::saveXML()函數(shù):
示例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
總結(jié)
以上是生活随笔為你收集整理的savexml php,PHP DOMDocument saveXML()用法及代码示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php数组去重的函数,php数组去重的函
- 下一篇: php 5.3.3 漏洞,PHP 5.3