• 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();
        }
    }
    
  • 相关阅读:
    (转)OpenCV提取视频每一帧及将连续图片合成视频
    OpenCV对图像的性能测试
    (转)OpenCV中的常用函数
    EasyX-加载图像实现人物行走
    “三行情书”——给你三行代码的爱恋~
    EasyX—模拟小球自由落体
    maven的pom.xml配置文件
    spring常用注解
    sql优化
    idea快捷键
  • 原文地址:https://www.cnblogs.com/zcy_soft/p/1951243.html
Copyright © 2020-2023  润新知