这是xml文件
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery>
<images>
<title><![CDATA[ ]]></title>
<description><![CDATA[ ]]></description>
<tmb>FphotoGallery/tmb1.jpg</tmb>
<img>FphotoGallery/img1.jpg</img>
</images>
<gallery>怎么用php在后面添加内容?
我这么写的
$dom = new DOMDocument('1.0');
$gallery = $dom->gappendChild($dom->createElement('gallery'));
$images = $gallery->gappendChild($dom->createElement('images'));
$title = $images->gappendChild($dom->createElement('title'));
$title->gappendChild($dom->createTextNode('<![CDATA[ ]]>'));
$description = $images->gappendChild($dom->createElement('description'));
$description->gappendChild($dom->createTextNode('<![CDATA[ ]]>'));
$tmb = $images->gappendChild($dom->createElement('tmb'));
$tmb->gappendChild($dom->createTextNode('FphotoGallery/a.jpg'));
$img = $images->gappendChild($dom->createElement('img'));
$img->gappendChild($dom->createTextNode('FphotoGallery/a.jpg'));
$dom->formatOutput = true;
$dom -> save('FphotoGallery.xml'); // save as file但是没有效果啊?是不是哪出问题了
<?xml version="1.0" encoding="iso-8859-1"?>
<gallery>
<images>
<title><![CDATA[ ]]></title>
<description><![CDATA[ ]]></description>
<tmb>FphotoGallery/tmb1.jpg</tmb>
<img>FphotoGallery/img1.jpg</img>
</images>
<gallery>怎么用php在后面添加内容?
我这么写的
$dom = new DOMDocument('1.0');
$gallery = $dom->gappendChild($dom->createElement('gallery'));
$images = $gallery->gappendChild($dom->createElement('images'));
$title = $images->gappendChild($dom->createElement('title'));
$title->gappendChild($dom->createTextNode('<![CDATA[ ]]>'));
$description = $images->gappendChild($dom->createElement('description'));
$description->gappendChild($dom->createTextNode('<![CDATA[ ]]>'));
$tmb = $images->gappendChild($dom->createElement('tmb'));
$tmb->gappendChild($dom->createTextNode('FphotoGallery/a.jpg'));
$img = $images->gappendChild($dom->createElement('img'));
$img->gappendChild($dom->createTextNode('FphotoGallery/a.jpg'));
$dom->formatOutput = true;
$dom -> save('FphotoGallery.xml'); // save as file但是没有效果啊?是不是哪出问题了
之后先$dom->load("FphotoGallery.xml");试试。
Fatal error: Call to undefined method DOMDocument::gappendChild() if (top.location == self.location)
如果数据更新比较快,就用PHP每次都生成这个XML好了
<?php
header ("content-type: text/xml");//关键是这个header
echo "<?xml version=\"1.0\" ?>";//这个,在linux系统下直接输出会出错,估计是标签问题。比较奇怪,所以就放echo里了。
?>
<all>
<data>
<cpu>
<![CDATA[<?php echo $my_cpu;?>]]>
</cpu>
<memory>
<![CDATA[<?php echo $my_mem;?>]]>
</memory>
<idle>
<![CDATA[<?php echo $my_idle;?>]]>
</idle>
<avail>
<![CDATA[<?php echo $my_avail;?>]]>
</avail>
</data>
</all>