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. CDR 2017压感笔和压感设备该怎么设置使用?

    您可以通过CorelDRAW 2017 中的以下工具来运用压感笔.笔或其他设备的压力:艺术笔(表达模式).橡皮擦.涂抹.转动.吸引.排斥.粗糙和弄脏.此外,您还可以通过艺术笔(表达模式)工具.橡皮擦. ...

  2. CorelDRAW X6冰点价加推800套燃爆6月

    CorelDRAW是迄今最具创意的图形设计程序,并获得所有行业的公认的知名工具.在刚刚结束的CorelDRAW X6限量活动之后,CorelDRAW官方继续加推800套CorelDRAW X6满足用户 ...

  3. div纵向居中的方法(转载)

    方法一这个方法把一些 div 的显示方式设置为表格,因此我们可以使用表格的 vertical-align property 属性. <div id="wrapper"> ...

  4. 路飞学城Python-Day37(practise)

    #1.自行创建测试数据 create database homework; use homework; # 年级表->老师表->课程表->班级表->学生表->成绩表-&g ...

  5. Javascript的jsonp原理

    Javascript的jsonp原理   首先JSON是一种基于文本的数据交换方式,或者叫做数据描述格式 当一个网页在请求JavaScript文件时则不受是否跨域的影响,凡是拥有”src”这个属性的标 ...

  6. 原生javaScript完成Ajax请求

    使用原生javaScript完成Ajax请求,首先应该创建一个对象XMLHttprequest,考虑到兼容低版本IE浏览器,使用ActiveXObject对象,代码入下: var request; i ...

  7. Ruby中写换行

    Ruby中写换行 print("Hello,\nRuby\n!\n") print("Hello, Ruby ! ") 这两个竟然是一样的:就是说,可以直接回车 ...

  8. IOS假设将一个十六进制的color转换成UIColor,非常有用

    UI给开发的效果图非常多时候标注着十六进制的Color,而程序中用到的往往是UIColor能够用例如以下方法去转换: (UIColor *)RGBColorFromHexString:(NSStrin ...

  9. 怎样用批处理来执行多个exe文件

    怎样用批处理来运行多个exe文件 @echo off start *****.exe start *****.exe start *****.exe start *****.exe 接着我们就能够运行 ...

  10. 从ORA-27300,ORA-27301到ORA-00064

        近期因为session数量添加,须要调整session,也就是要调整process參数. 看是比較简单的一个问题,却遭遇了ORA-27300,ORA-27301.因为这个涉及到了有关内核參数k ...