Posts Tagged ‘xml



<?php /* 作者: qk31 作用:数据库数据生成xml文件进行简单的封装 */ class xmlCreate { var $msg; var $encode; var $sumMsg; function xmlCreate($encode,$array,$sum) { $this->setXmlHeader($encode);//设置编码 $this->setSumMsg($sum); //设置记录总数 $this->setMsg($array); //设置留言信息处理 } /*设定xml的编码和头部*/ function setXmlHeader($encode) { header(“Content-Type:text/html;charset=$encode”); header(“Content-type: text/xml”); $this->msg.=”<?xml version=\”1.0\” encoding=\”$encode\”?>”; } /*设定生成xml文件*/ function setMsg($array) { $this->msg.=”<main>”; $this->msg.=”<nums>”.$this->sumMsg.”</nums>”; $this->xmlAddTag($array); $this->msg.=”</main>”; } /*为数据库字段添加xml标签*/ function xmlAddTag($array) { $i=1; foreach ($array as $row) { $this->msg.=”<row [...]

例子来源:<<ajax in action>>第十二章使用xslt的动态搜索 程序结构: 利用php根据ajax发过来的请求生成一个xml文件 xml格式如下:   QUOTE: <?xml version=”1.0″ ?> <phonebook> <entry id=’1′>   <company>ABC</company>   <contact>Dave Crane</contact>   <country>UK</country>   <phone>123456789</phone> </entry> <entry id=’2′>   <company>XYZ</company>   <contact>Eric Pascarello</contact>   <country>USA</country>   <phone>123456789</phone> </entry> </phonebook> 再套用xsl,样式表(类似于css) QUOTE: <?xml version=”1.0″ encoding=”ISO-8859-1″?> <xsl:stylesheet version=”1.0″ xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”> <xsl:template match=”/”> <!——-这里是对表格标题定义——>     <table id=”table1″>       <tr>         <th align=”left”>Company</th>         <th align=”left”>Contact</th> [...]


About this blog

QK31欢迎你的到来.

Photostream

search_extends

 

2010年九月
« 八    
 12345
6789101112
13141516171819
20212223242526
27282930  

36
Unique
Visitors
Powered By Google Analytics

分类目录

标签云