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 [...]

例子来源:<<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>
        <th align=”left”>Country</th>
        <th align=”left”>Phone</th>        
      </tr>
<!——这里是对字段循环结合xml内容输出数据——->
      <xsl:for-each select=”phonebook/entry”>
      <tr>
        <td><xsl:value-of select=”company”/></td>
        <td><xsl:value-of select=”contact”/></td>
        <td><xsl:value-of select=”country”/></td>
        <td><xsl:value-of select=”phone”/></td>
      </tr>
     [...]


About this blog

QK31欢迎你的到来.

Photostream

Flash MP3 Player JW

Here is the Music Player. You need to installl flash player to show this cool thing!

search_extends

 

2010年三月
« 二    
1234567
891011121314
15161718192021
22232425262728
293031  

分类目录

标签云


28
Unique
Visitors
Powered By Google Analytics