Page 1 of 1

How can I add tag <image> into the XML file?

Posted: Fri May 26, 2006 9:12 am
by nskauto
Hello guys, please help me.

I have the flash template for Slideshow, but this template uses XML file, where stored paths to images.

XML:

Code: Select all

<gallery timer="1" order="sequential" fadetime="18" looping="yes" xpos="0" ypos="0">
<image path="images/calliandra.jpg" />
<image path="images/dombeya.jpg" />
<image path="images/strelitzia.jpg" />
<image path="images/trensa.jpg" />
<image path="images/treeflower.jpg" />
<image path="images/bellflowers.jpg" />
<image path="images/cordyline.jpg" />
<image path="images/forsythia.jpg" />
</gallery>
I need to understand a simple PHP code to add automatically tag <image path="blabla"> into this XML file .....

Can anybody help me ?

Thank you all.

Posted: Fri May 26, 2006 9:31 am
by xpgeek
See XML with expat

This class is meant to read and write XML documents implementing the DOM API using the PHP XML functions based on the Expat library.

The class is able to open an XML document, parses it, and lets the developer change anything in the document: add nodes, set attributes, remove attributes, clone nodes, insert children, etc..

Posted: Fri May 26, 2006 9:43 am
by nskauto
I think there are several lines of code. :(( Please post this simple lines if you know

Read, edit and write xml file.

Posted: Fri May 26, 2006 10:50 am
by xpgeek
nskauto wrote:I think there are several lines of code. :(( Please post this simple lines if you know
Try it. :D

Code: Select all

$dom = new DomDocument();
$dom->load("article.xml");

$item = $dom->createElement("image");
$item->setAttribute ('path', 'images/someimage.jpg');
$dom->documentElement->appendChild($item);

print $dom->saveXML();
article.xml look like this :)
<gallery timer="1" order="sequential" fadetime="18" looping="yes" xpos="0" ypos="0">
<image path="images/calliandra.jpg" />
<image path="images/dombeya.jpg" />
<image path="images/strelitzia.jpg" />
<image path="images/trensa.jpg" />
<image path="images/treeflower.jpg" />
<image path="images/bellflowers.jpg" />
<image path="images/cordyline.jpg" />
<image path="images/forsythia.jpg" />
</gallery>

Posted: Mon May 29, 2006 1:30 am
by nskauto
But I have such errors :(( :

Warning: domdocument() expects at least 1 parameter, 0 given in C:\Inetpub\vhosts\sokieva.bagov.net\httpdocs\test\test.php on line 2
Fatal error: Call to undefined function: load() in C:\Inetpub\vhosts\sokieva.bagov.net\httpdocs\test\test.php on line 3

What happens ? :(

Posted: Mon May 29, 2006 2:13 am
by xpgeek
my version php is 5.1.2

Posted: Mon May 29, 2006 5:37 am
by nskauto
But my PHP Version is 4.3.11.

So in PHP 4 there are others methods and functions :(( Can anybody help me with PHP4?

Posted: Mon May 29, 2006 10:33 am
by Ambush Commander
I believe the standard XML library for PHP 4 is expat: http://us2.php.net/manual/en/ref.xml.php

You can also try using one of the many PEAR pure PHP XML parsing classes (they're kind of slow though): http://pear.php.net/packages.php?catpid=22&catname=XML