php loadxml <,PHP DOMDocument loadXML()用法及代码示例

DOMDocument::loadXML()函数是PHP中的内置函数,用于从字符串中加载XML文件。

用法:

mixed DOMDocument::loadXML( string $source, int $options = 0 )

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

$source:此参数保存包含XML文档的字符串。

$options:此参数保存libxml选项常量的按位或。

返回值:如果成功,则此函数返回TRUE;如果失败,则返回FALSE。如果以静态方式调用该函数,则返回DOMDocument;如果失败,则返回FALSE。

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

示例1:

// Create a new DOMDocument

$doc = new DOMDocument();

// Load the XML file

$doc->loadXML(

"

Geeks123

GeeksforGeeks

+91-XXXXXXXXXX

abc@geeksforgeeks.org

");

// Create XML file and display it

echo $doc->saveHTML();

?>

输出:

Geeks123

GeeksforGeeks

+91-XXXXXXXXXX

abc@geeksforgeeks.org

示例2:

// Create new DOMDocument

$doc = new DOMDocument();

// Create a comment document

$comm1 = $doc->createComment('Starting of XML document');

// Append element to the document

$doc->appendChild($comm1);

// Create XML file and display it

echo $doc->saveHTML();

// Load the XML file

$doc->loadXML(

"

Geeks123

GeeksforGeeks

+91-XXXXXXXXXX

abc@geeksforgeeks.org

");

// Create comment element

$comm2 = $doc->createComment('Ending of XML document');

// Append element to the document

$doc->appendChild($comm2);

// Create XML element and display it

echo $doc->saveHTML();

?>

输出:

Geeks123

GeeksforGeeks

+91-XXXXXXXXXX

abc@geeksforgeeks.org

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值