php 在原有xml文件中追加节点
来源:互联网 发布:淘宝店铺广告联盟 编辑:程序博客网 时间:2024/04/30 12:24
<?php
$xmlpatch = 'index.xml';
$doc = new DOMDocument();
$doc -> formatOutput = true;
if($doc -> load($xmlpatch)) {
$document = $doc -> documentElement;//获得根节点(root)
for($i=1;$i<10;$i++){
$item=$doc->createElement("item");
$item=$document->appendChild($item);
$date1=$doc->createAttribute("id");
$date1=$item->appendChild($date1);
$date1->appendChild($doc->createTextNode($i));
//操作
$webName=$doc->createElement("op");
$webName=$item->appendChild($webName);
$webName->appendChild($doc->createTextNode("add"));
$url = $doc -> createAttribute('url');//新建属性
$patch = $doc -> createTextNode("http://domain/".$i);//新建TEXT值
$url -> appendChild($patch);//将$patch文本设为$url属性的值
$webName->appendChild($url);
$id = $doc -> createAttribute('id');
$newsid = $doc -> createTextNode($i);
$id -> appendChild($newsid);
$webName->appendChild($id);
//影片质量
$webName=$doc->createElement("att");
$webName=$item->appendChild($webName);
$webName->appendChild($doc->createTextNode("hd"));
$title = $doc -> createAttribute('title');
$newstitle = $doc -> createTextNode('title'.$i);
$title -> appendChild($newstitle);
$sendtime = $doc -> createAttribute('time');
$newssendtime = $doc -> createTextNode(time());
$sendtime -> appendChild($newssendtime);
$webName->appendChild($title);
$webName->appendChild($sendtime);
//片名
$webName=$doc->createElement("title");
$webName=$item->appendChild($webName);
$webName->appendChild($doc->createCDATASection('title'.$i));
$author = $doc -> createAttribute('author');
$newsauthor = $doc -> createTextNode('author'.$i);
$author -> appendChild($newsauthor);
$webName->appendChild($author);
//dc:creator
$creator = $doc->createElement("dc:creator");
$creator = $item->appendChild($creator);
$creator->appendChild($doc->createCDATASection('dcauthor'.$i));
$document->appendChild($item);
}
}
$doc -> save($xmlpatch);//保存文件
echo $xmlpatch . ' has add success';
?>
$xmlpatch = 'index.xml';
$doc = new DOMDocument();
$doc -> formatOutput = true;
if($doc -> load($xmlpatch)) {
$document = $doc -> documentElement;//获得根节点(root)
for($i=1;$i<10;$i++){
$item=$doc->createElement("item");
$item=$document->appendChild($item);
$date1=$doc->createAttribute("id");
$date1=$item->appendChild($date1);
$date1->appendChild($doc->createTextNode($i));
//操作
$webName=$doc->createElement("op");
$webName=$item->appendChild($webName);
$webName->appendChild($doc->createTextNode("add"));
$url = $doc -> createAttribute('url');//新建属性
$patch = $doc -> createTextNode("http://domain/".$i);//新建TEXT值
$url -> appendChild($patch);//将$patch文本设为$url属性的值
$webName->appendChild($url);
$id = $doc -> createAttribute('id');
$newsid = $doc -> createTextNode($i);
$id -> appendChild($newsid);
$webName->appendChild($id);
//影片质量
$webName=$doc->createElement("att");
$webName=$item->appendChild($webName);
$webName->appendChild($doc->createTextNode("hd"));
$title = $doc -> createAttribute('title');
$newstitle = $doc -> createTextNode('title'.$i);
$title -> appendChild($newstitle);
$sendtime = $doc -> createAttribute('time');
$newssendtime = $doc -> createTextNode(time());
$sendtime -> appendChild($newssendtime);
$webName->appendChild($title);
$webName->appendChild($sendtime);
//片名
$webName=$doc->createElement("title");
$webName=$item->appendChild($webName);
$webName->appendChild($doc->createCDATASection('title'.$i));
$author = $doc -> createAttribute('author');
$newsauthor = $doc -> createTextNode('author'.$i);
$author -> appendChild($newsauthor);
$webName->appendChild($author);
//dc:creator
$creator = $doc->createElement("dc:creator");
$creator = $item->appendChild($creator);
$creator->appendChild($doc->createCDATASection('dcauthor'.$i));
$document->appendChild($item);
}
}
$doc -> save($xmlpatch);//保存文件
echo $xmlpatch . ' has add success';
?>
0 0
- php 在原有xml文件中追加节点
- 在XML中增加节点 . 在原有的XML文件中,根据节点,添加数据
- PHP中利用simpleXML读取XML和追加XML节点
- php中在文件追加时候换行
- php对xml文件中节点编辑
- 用libxml2写xml文件时在节点后追加回车
- php 追加内容到txt文件中
- php 追加内容到txt文件中
- XML 追加节点 带缩进
- 在hibernate的映射文件中追加字符编码以xml格式
- 简单的XML文件操作(xml文件生成,节点追加、遍历、修改、删除)
- PHP追加写文件
- Java 往文件中写数据,新写入的数据总是覆盖原有数据,实现追加功能
- C# winform 在xml文件中根据指定节点名查找节点名以及值
- PHP DOM 读写XML文件 节点属性
- XML+xsl 追加节点后转HTML
- 使用Qt写Xml文档,追加节点。
- 如何在php文件中完全显示xml的结构
- XML之DTD
- OC下载网络数据简介
- 手机传感器大科普:手机中的陀螺仪、加速器和磁力计
- 在windows上编译32位和64位mono
- Service要点全解析
- php 在原有xml文件中追加节点
- MVC3+AutoFac实现程序集级别的依赖注入
- 8 个必备的PHP功能开发
- iOS-将像素绘制到屏幕上
- Wonderware配置-Intouch读取数据 6
- ConfigurationChanged流程梳理(屏幕旋转、语言及字体切换)
- PHP开发者应了解的24个库
- HTML+CSS基础(五):表单标签,与用户交互
- UIWebView-JSContext实现OC与JS交互