<?xml version="1.0" encoding="utf-8"?>
<photos path="flash/images/">
<photo name="Photo 1" url="1.jpg">This is the optional description for photo 1</photo>
<photo name="Photo 2" url="2.jpg">This is the optional description for photo 2</photo>
<photo name="Photo 3" url="3.jpg">This is the optional description for photo 3</photo>
<photo name="Photo 4" url="4.jpg">This is the optional description for photo 4</photo>
<photo name="Photo 5" url="5.jpg">This is the optional description for photo 5</photo>
<photo name="Photo 6" url="6.jpg">This is the optional description for photo 6</photo>
</photos>
怎么用php生成,因为我要还图片的,每次修改xml文件麻烦
<photos path="flash/images/">
<photo name="Photo 1" url="1.jpg">This is the optional description for photo 1</photo>
<photo name="Photo 2" url="2.jpg">This is the optional description for photo 2</photo>
<photo name="Photo 3" url="3.jpg">This is the optional description for photo 3</photo>
<photo name="Photo 4" url="4.jpg">This is the optional description for photo 4</photo>
<photo name="Photo 5" url="5.jpg">This is the optional description for photo 5</photo>
<photo name="Photo 6" url="6.jpg">This is the optional description for photo 6</photo>
</photos>
怎么用php生成,因为我要还图片的,每次修改xml文件麻烦
http://www.php.net/manual/en/domdocument.createelement.php
$xml = new XMLWriter();
$xml->openURI('filename.xml');
$xml->startDocument('1.0', 'utf-8');
$xml->startElement('photos');
$xml->setAttribute('path', "flash/images/");
foreach($photoEles as $attr)
{
$xml->startElement('photo'); }
// 不写了,看电影去
[User:root Time:09:32:09 Path:/home/liangdong/php]$ php writer.php
<?xml version="1.0" encoding="utf8"?>
<photos path="flash/images/"><photo name="photo1" url="1.jpg">text1</photo><photo name="photo2" url="2.jpg">text2</photo><photo name="photo3" url="3.jpg">text3</photo><photo name="photo4" url="4.jpg">text4</photo><photo name="photo5" url="5.jpg">text5</photo><photo name="photo6" url="6.jpg">text6</photo></photos>[User:root Time:09:32:10 Path:/home/liangdong/php]$ cat writer.php
<?php
$xml = new XMLWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'utf8');
$xml->startElement('photos');
$xml->writeAttribute ('path', 'flash/images/');
foreach (range(1, 6) as $index) {
$xml->startElement('photo');
$xml->writeAttribute('name', 'photo' . $index);
$xml->writeAttribute('url', $index . ".jpg");
$xml->text('text' . $index);
$xml->endElement();
}
$xml->endElement();
$str = $xml->flush();
echo $str;
?>第一次见, 用了一下, 和expat, xmpp-nad的风格一样, 创建XML很方便.
xml.php文件
<?php
@header("Expires: -1");
@header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE);
@header("Pragma: no-cache");
@header("Content-type: application/xml; charset=gb2312");
//header("Content-type: text/xml");
require dirname(__FILE__).'/../include/Inc.php';'连接数据库
$ppid = Replace_Text($_GET['ppid']);
echo "<?xml version=\"1.0\" encoding=\"gb2312\" ?>\n";
echo "<data>\n";
echo "<channel>\n";
$strSql1 ="select l_url,l_title,l_pic from friendlink where l_pid='18' and l_ppid='74' and l_flag='1' order by l_num asc";
$res1 = _query($strSql1);
while(!!$rs1=_fetch_array($res1)){
$pic = $rs1['l_pic'];
$url = $rs1['l_url'];
echo "<item>\n";
echo "<link>".$url."</link>\n";
echo "<image>/Upfiles/logoPic/".$pic."</image>\n";
echo "<title>ws</title>\n";
echo "</item>\n";
}
echo "</channel>\n";
mysql_free_result($res1);
?>flash那个XML的src文件就是 你上面的这个PHP文件
XML.php