Page 1 of 1

XML and PHP 5

Posted: Sat May 08, 2010 10:23 pm
by samir_gambler
I need to append a new node to existing XML file with the help of PHP 5. I am new to DOM. Can anyone plz guide me.....

MY xml file is play.xml

Code: Select all

<rss version="2.0">
<channel>
<title>Title of page</title>
<link>http://www.foo.com</link>
<description>Description of page</description>
    <item>
        <title>Story about something</title>
        <link>#</link>
        <enclosure url="demo.flv"
        type="video/quicktime"/>
    </item>
    <item>
        <title>The Wolfman</title>
        <link>#</link>
        <enclosure url="wolfman.flv"
        type="video/quicktime"/>
    </item>
</channel>
</rss>

Re: XML and PHP 5

Posted: Sun May 09, 2010 2:02 am
by Zyxist
There are a lot of tutorials that explain how to use DOM:

http://devzone.zend.com/article/2387-XML-and-PHP-5
http://www.w3schools.com/php/php_xml_dom.asp

They should help you start. Remember that DOM is a language-independent API, which means that you could take a tutorial for a different language and simply do exactly the same in PHP. On W3Schools, there is a tutorial for DOM, where you find concrete information how to append a node.

Re: XML and PHP 5

Posted: Sun May 09, 2010 11:47 am
by samir_gambler
i am able to append new node to XML file but have some issue in RSS + Media XML file
My RSS+Media xml file is

Code: Select all

<rss version="2.0">
<channel>
<title>Title of page</title>
<link>http://www.foo.com</link>
<description>Description of page</description>
    <item>
        <title>Story about something</title>
        <link>#</link>
        <enclosure url="demo.flv"
        type="video/quicktime"/>
    </item>
    <item>
        <title>The Wolfman</title>
        <link>#</link>
        <enclosure url="wolfman.flv"
        type="video/quicktime"/>
    </item>
</channel>
</rss>
My php code for appending new entry is

Code: Select all

$dom = new DomDocument();
$dom->load("articles.xml");
$item = $dom->createElement("item");
$title = $dom->createElement("title");
$titletext = $dom->createTextNode("XML in PHP5");
$title->appendChild($titletext);
$item->appendChild($title);
$title = $dom->createElement("link");
$titletext = $dom->createTextNode("samir");
$title->appendChild($titletext);
$item->appendChild($title);
//$item = $dom->createElement("enclosure url=\"wolfman.flv\" type=\"video/quicktime/");
$dom->documentElement->appendChild($item);
//print $dom->saveXML();
$dom->save("articles.xml")
i am unable to add <enclosure url=.....\> information plz help its really urgent...

Re: XML and PHP 5

Posted: Sun May 09, 2010 12:36 pm
by Weirdan