php xml 的基本操作类
class xmlMessage{
protected $doc;
protected $rootKey;
public function __construct() {
$this->doc = new DOMDocument('1.0', 'utf-8');
$this->doc -> formatOutput = true;
$status = $this->doc -> createElement('status');//create new key
$this->rootKey = $status;
$this->doc->appendChild($status);
}
public function createSon($sonName, $value){
$this->deleteChild($sonName);
$sonKey = $this->doc -> createElement($sonName);//新建节点
$content = $this->doc -> createTextNode($value);//节点值
$sonKey -> appendChild($content);
$this->rootKey->appendChild($sonKey);
}
public function appendNodeValue($tagName, $appendValue){
if(!$this->hasNodeName($tagName)){
$this->createSon($tagName, '');
}
$this->rootKey->getElementsByTagName($tagName)->item(0)->nodeValue .= "\n".$appendValue;
}
public function editNodevalue($tagName, $value){
if(!$this->hasNodeName($tagName)){
$this->createSon($tagName, '');
}
$this->rootKey->getElementsByTagName($tagName)->item(0)->nodeValue = $value;
}
public function deleteChild($tagName){
if($this->hasNodeName($tagName))
$this->rootKey -> removeChild($this->rootKey->getElementsByTagName($tagName)->item(0));
}
private function hasNodeName($tagName){
$hasNode = false;
$tempList = $this->doc->getElementsByTagName($tagName);
foreach($tempList as $temp){
if($temp->nodeName == $tagName)
$hasNode = true;
}
return $hasNode;
}
public function setNodesByArray($xmlArray){
$now = getdate(time());
$dataCreated = $now['year'].'/'.$now['mon'].'/'.$now['mday'].' '.$now['hours'].':'.$now['minutes'].':'.$now['seconds'];
$this->createSon('language', strtolower($xmlArray['basicInfo']['language']));
$this->createSon('source', $xmlArray['basicInfo']['source']);
$this->createSon('resumeUrl', $xmlArray['basicInfo']['resumeUrl']);
$this->createSon('email', $xmlArray['basicInfo']['email']);
$this->createSon('resumeGuid', $xmlArray['basicInfo']['resumeGuid']);
$this->createSon('dateCreated', $dataCreated);
$this->createSon('success','TRUE');
}
public function getXML(){
return $this->doc->saveXML();
}
}
php xml 的基本操作类的更多相关文章
- 让Visual Studio 2013为你自动生成XML反序列化的类
Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: 1. 在代码编辑界面的右侧滚动条上显示不同颜色的标签,让开发人员可以对所编辑文档的修改.查找.定位情 ...
- XML格式示例 与 XML操作(读取)类封装
header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...
- c# XML和实体类之间相互转换(序列化和反序列化)[砖]
link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...
- C# XML和实体类之间相互转换(序列化和反序列化)
我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...
- 自动生成XML反序列化的类
原文地址:http://www.cnblogs.com/jaxu/p/3632077.html Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: ...
- Xml通用操作类
using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml ...
- 利用MyEclipse连接数据库并自动生成基于注解或者XML的实体类
一.利用MyEclipse连接数据库 1. 打开MyEclipse的数据库连接视图 然后在Other中找到"MyEclipse Database"中的DB Browser 2. 在 ...
- XML和实体类之间相互转换(序列化和反序列化)
我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...
- 转载 VC轻松解析XML文件 - CMarkup类的使用方法
VC轻松解析XML文件 - CMarkup类的使用方法http://www.cctry.com/thread-3866-1-1.html VC解析XML文件的工具有很多,CMarkup, tinyXM ...
随机推荐
- php方法-------将汉字转为拼音或者提取汉字首字母
将汉字转为全拼,提取汉字首字母 <?php /** * 基于PHP语言的汉语转拼音的类 * 兼容 UTF8.GBK.GB2312 编码,无须特殊处理 * 对中文默认返回拼音首字母缩写,其它字符不 ...
- php基础-------preg_replace()与preg_replace_callback()
1.preg_replace() 执行一个正则表达式的搜索和替换. 语法: mixed preg_replace ( mixed $pattern , mixed $replacement , mix ...
- jquery的animate能渐变background-color
在freecodecamp 上学习复习时,写了一个demo,引用了 jquery 实现 color 的渐变动画,然后运行测试的时候,发现其他功能都正常,就是无法是实现颜色的动画. 如: $('butt ...
- Django框架详解之views
一个简单的视图 一个视图函数,是一个简单的python函数,它接受web请求并且返回web响应.无论视图本身包含什么逻辑,都要返回响应.为了将代码放在某处,约定是将视图放置在项目或应用程序目录中的名为 ...
- 2、Attentive Group Recommendation----注意力集中的群组推荐
1.摘要: 采用attention和NCF结合解决群组偏好融合的问题. 贡献: 第一个使用神经网络学习融合策略的组推荐. 进一步整合用户-项目交互改进组推荐,减轻冷启动问题. 2.方法: 模型AGRE ...
- 池(Pool)
#1 就是一个资源的集合,用的时候按照你的需要去取,用完了给人家放回去 #2 学编程的时候,老师给我们的解释过池的意思,大概是: 如果你喝水,你可以拿杯子去水龙头接.如果很多人喝水,那就只能排队去接. ...
- C语言基本语法——预处理器和预处理指令
1.什么是预处理器 2.什么是预处理器指令 3.预处理器指令 4.宏指令 5.宏函数 6.宏函数的优缺点 7.条件编译指令 1.什么是预处理器 • 预处理器是一个程序,用来处理源程序中的预处理指令. ...
- 一些css布局
# css布局 #---bootstrap 详情请看官方文档---首先要按照相应的官方规范引入相应的css js fonts等 container相当于一个容器 一般设置一个 接下来设置行 用ro ...
- spring boot和maven的约定大于配置体现在哪些方面
spring boot和maven的约定大于配置体现在哪些方面? 两者都遵从了约定大于配置的路线 约定优于配置体现点: 1.maven的目录文件结构 1)默认有resources文件夹,存放资源配置文 ...
- 彻底理解tomcat是怎样多线程处理http请求并将代码执行到controller里的的
彻底理解tomcat是怎样多线程处理http请求并将代码执行到controller里的的 1.线程池,thread = threadPool.getThread(),thread.executeHtt ...