时间:2021-05-26
本文实例讲述了php实现的xml操作类。分享给大家供大家参考,具体如下:
<?phpclass xml{var $version;var $encoding;var $start;var $end;var $filename;var $xml_document;var $root_start;var $root_end;var $rss_start;var $rss_end;function xml($ver='1.0',$encoding='GB2312'){ $this->version="<?xml version=/"{$ver}/" encoding=/"{$encoding}/" standalone=/"yes/" ?>"; $this->rss_start="<rss version=/"2.0/" xmlns:domxml=/"[url]http://xml.666life.com/rss/1.0[/url]/" xmlns:geo=/"[url]http://www.w3.org/2003/01/geo/wgs84_pos#[/url]/">"; $this->rss_end="</rss>";}function new_xml($filename){ $this->filename=$filename; return true;}function root($element){ $element=$this->filter($element); if(isset($this->start) and isset($this->end)){ exit("error:Only one top level element is allowed in an XML document./r/n"); }else{ $this->start="<$element>"; $this->end="</$element>"; $this->xml_document=$this->version."/n".$this->rss_start."/n".$this->start."/n"; return true; }}function append_root_node($title,$property=null,$pro_val=null){ $title=$this->filter($title); $property=$this->filter($property); $pro_val=$this->filter($pro_val); $property!=null?$pro_str=" $property=/"$pro_val/"":$property=null; $contents="<{$title}{$pro_str}>/n"; $this->xml_document.=$contents; $this->root_end="</$title>"; return true;}function append_root_node_end(){ $this->xml_document.=$this->root_end."/n"; return true;}function append_child_node($title='undefined',$contents='undefined',$property=null,$pro_val=null,$cddate=false){ isset($property)?$pro_str=" $property=/"$pro_val/"":$property=null; $title=$this->filter($title); $contents=$this->filter($contents,false); $property=$this->filter($property); $pro_val=$this->filter($pro_val); $cddate===false?$cddate=false:$cddate=true; if($cddate){ $contents="<{$title}{$pro_str}><!--[CDATA['/n$contents/n']]--></$title>/n"; }else{ $contents="<{$title}{$pro_str}>$contents</$title>"; } $this->xml_document.=$contents."/n"; return true;}function display(){ header("Content-type: text/xml"); $xml=$this->xml_document.$this->end."/n".$this->rss_end; echo $xml; //return true;}function filter($sring,$replace_null=true){ $filter[]='"'; $filter[]="//"; $filter[]="/n"; $filter[]="/r"; $filter[]="/t"; $replace_null===true?$filter[]=" ":$replace_null=false; foreach ($filter as $val){ $sring=str_replace($val,'',$sring); } return $sring;}function encode(){ //you can add the convert encode function here or add other class to do that}function save(){ $this->xml_document=$this->xml_document.$this->end."/n".$this->rss_end; $handle=fopen($this->filename,'wb+'); $result=fwrite($handle,$this->xml_document); fclose($handle); if($result){ return true; }else{ echo "error:can't write to files,maybe the access denied.try to chmod 777 the directory?"; return false; }}}更多关于PHP操作xml相关内容感兴趣的读者可查看本站专题:《PHP针对XML文件操作技巧总结》
希望本文所述对大家PHP程序设计有所帮助。
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了PHP实现的XML操作类。分享给大家供大家参考,具体如下:这是一个接口程序,需要大量分析解析XML,PHP的xml_parse_into_stru
近期在看PHP的教学视频,其中讲到了PHP操作xml文档,学了点儿DOMDocument类。自己查手册又全英文,看不大懂。但还是自己写了个类,实现了查找xml节
本文实例讲述了php实现的XML操作(读取)封装类。分享给大家供大家参考,具体如下:Normal|DRWondershareVedioConvertorWond
本文实例讲述了PHP封装的XML简单操作类。分享给大家供大家参考,具体如下:xml_dom.php封装类文件:dbfile=$db_file;if(!file_
本文实例讲述了php中Array2xml类实现数组转化成XML的方法。分享给大家供大家参考。具体实现方法如下:复制代码代码如下:xml='';$this->xm