php 创建 xml 文件

来源:互联网 发布:中银淘宝信用卡申请 编辑:程序博客网 时间:2024/05/16 08:46
<?php$dom = new DOMDocument('1.0','utf-8');//1.创建文本节点$nameT = $dom -> createTextNode('刘备');//2.创建普通节点$name = $dom -> createElement('name');//append$name->appendChild($nameT);//1.创建CDATA节 $cdata = $dom -> createCDATASection("'我是c'd,<data节");//2.创建普通节点$intro = $dom -> createElement('intro');//append$intro -> appendChild($cdata);//3.创建 character 节点 也是 普通节点$char = $dom -> createElement('character');//append$char->appendChild($name);$char->appendChild($intro);//4.创建属性节点$attr = $dom -> createAttribute('age');$attr->value=56;//append$char->appendChild($attr);//5 把 节点 append 到 dom节点上去$dom -> appendChild($char);header('Content-type:text/xml');echo $dom->savexml();?>

原创粉丝点击