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 的基本操作类的更多相关文章

  1. 让Visual Studio 2013为你自动生成XML反序列化的类

    Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: 1. 在代码编辑界面的右侧滚动条上显示不同颜色的标签,让开发人员可以对所编辑文档的修改.查找.定位情 ...

  2. XML格式示例 与 XML操作(读取)类封装

    header('Content-Type: text/xml'); <?xml version="1.0" encoding="utf-8" standa ...

  3. c# XML和实体类之间相互转换(序列化和反序列化)[砖]

    link: http://blog.okbase.net/haobao/archive/62.html by: 好饱 我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlU ...

  4. C# XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. using System; using System.Collections.Ge ...

  5. 自动生成XML反序列化的类

    原文地址:http://www.cnblogs.com/jaxu/p/3632077.html   Visual Sutdio 2013增加了许多新功能,其中很多都直接提高了对代码编辑的便利性.如: ...

  6. Xml通用操作类

    using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Xml ...

  7. 利用MyEclipse连接数据库并自动生成基于注解或者XML的实体类

    一.利用MyEclipse连接数据库 1. 打开MyEclipse的数据库连接视图 然后在Other中找到"MyEclipse Database"中的DB Browser 2. 在 ...

  8. XML和实体类之间相互转换(序列化和反序列化)

    我们需要在XML与实体类,DataTable,List之间进行转换,下面是XmlUtil类,该类来自网络并稍加修改. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ...

  9. 转载 VC轻松解析XML文件 - CMarkup类的使用方法

    VC轻松解析XML文件 - CMarkup类的使用方法http://www.cctry.com/thread-3866-1-1.html VC解析XML文件的工具有很多,CMarkup, tinyXM ...

随机推荐

  1. Thinkphp开源框架如何使用?

    (一)首先是准备工作下载thinkPHP框架最新版本,解压缩到你将要开发的项目位置.杭州php操作演示如图: 其中index.php是入口文件,即所有的请求都要经过此文件才能够完成.Applicati ...

  2. BZOJ 4229: 选择 LCT_独创方法_边双

    考虑如果两点在一个环中,那么这两点一定可以构出双联通分量. 考虑环和环镶嵌,那么两个环中的点一定都互为双联通分量. 由此,我们想到一个算法: 将删边转为反向加边,用LCT维护图. 当我们连接两个点时, ...

  3. (翻译) Inheritance and the prototype chain 继承和原型链

    JavaScript is a bit confusing for developers experienced in class-based languages (like Java or C++) ...

  4. is == id 的用法;代码块;深浅copy;集合

    1 内容总览 is == id 用法 代码块 同一代码块下的缓存机制 (字符串驻留机制) 不同代码块下的缓存机制 (小数据池) 总结 集合(了解) 深浅copy 2 具体内容 id is == # i ...

  5. Vue双向绑定原理(源码解析)---getter setter

       Vue双向绑定原理      大部分都知道Vue是采用的是对象的get 和set方法来实现数据的双向绑定的过程,本章将讨论他是怎么利用他实现的. vue双向绑定其实是采用的观察者模式,get和s ...

  6. Mysql学习总结(30)——MySQL 索引详解大全

    什么是索引? 1.索引 索引是表的目录,在查找内容之前可以先在目录中查找索引位置,以此快速定位查询数据.对于索引,会保存在额外的文件中. 索引,是数据库中专门用于帮助用户快速查询数据的一种数据结构.类 ...

  7. PatentTips - Increasing turbo mode residency of a processor

    BACKGROUND Many modern operating systems (OS's) use the Advanced Configuration and Power Interface ( ...

  8. angular-数据库

    <div ng-app="myApp" ng-controller="customersCtrl"> <table> <tr ng ...

  9. Android 中模仿 Twitter 实现 Toolbar Indicator

    项目地址:https://github.com/nekocode/ToolbarIndicator

  10. UE4在VS2013中各个编译配置代表意义

    UE4中有个各式各样的编译配置,都怎么个意思呢? 对原文的理解和翻译. https://docs.unrealengine.com/latest/INT/Programming/Development ...