Page 1 of 1

create an xml tag with colon using php

Posted: Thu Oct 05, 2006 5:40 am
by madhu
HI all,

Please help me how to create an xml tag with colon.


CODE:

<?php
$doc=new DomDocument('1.0','iso-8859-1');
$rss=$doc->createElement('rss');
$rss=$doc->appendChild($rss);
$mediacontent=$doc->createElement('media:content');
$mediacontent=$rss->appendChild($mediacontent);
?>


ERROR:

Its giving reference to undeclared namespace prefix:'media'.

Please help me how to solve this issue.

Waiting for your positive replies.........

Thanks and regards
MADHU

Posted: Thu Oct 05, 2006 5:44 am
by volka
http://www.feedforall.com/mediarss.htm
Declaration: The name space for Media RSS is defined at http://search.yahoo.com/mrss

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss">
Take a look at http://de2.php.net/manual/en/function.d ... espace.php

Posted: Thu Oct 05, 2006 5:50 am
by madhu
am able to generate

<rss>
<media url="http://d.yimg.com/us.yimg.com/p/ap/2006 ... 3C9pMxoA--" type="image/jpeg" height="91" width="130" />
</rss>

but when i was trying like,

<rss>
<media:content url="http://d.yimg.com/us.yimg.com/p/ap/2006 ... 3C9pMxoA--" type="image/jpeg" height="91" width="130" />
</rss>


its giving the error

Posted: Thu Oct 05, 2006 6:19 am
by volka
yes, because the namespace media is not defined.
namespace:name
media:content

Posted: Thu Oct 05, 2006 7:23 am
by madhu
Dear sir,

Can you please tell me how to define namespace??

Posted: Thu Oct 05, 2006 7:26 am
by volka
madhu wrote:Can you please tell me how to define namespace??
No, sorry, I can't. Since switching to php 5 I haven't used domxml.
But

Posted: Fri Oct 06, 2006 3:38 am
by madhu
Hi all,

If anybody knows how to print an XML tag with (:) symbol in the tag,then please help me.

Am searching from the last 2 days in Google.

But am not getting.

Please reply ASAP...........

Thanks and regards
MADHU

Posted: Fri Oct 06, 2006 6:59 am
by volka
I can tell you how to do it with php5's DOM.
You have to declare the namespace first, i.e. add the attribute xmlns:media with the url to the definition (xmlns, xml namespace).
The namespace for Media RSS is defined to be: http://search.yahoo.com/mrss/

For example:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
http://de2.php.net/manual/en/function.d ... espace.php probably would have done this for you.

Code: Select all

<?php
$dom = new DOMDocument('1.0', 'iso-8859-1');
$rss = $dom->createElement('rss');
$rss->setAttribute('version', '2.0');
// declaring the namespace media
$rss->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/');

// creating an element in the namespace media
$content = $dom->createElement('media:content');
$content->setAttribute('url', 'http://www.php.net');

$rss->appendChild($content);
$dom->appendChild($rss);

$dom->formatOutput=true;
echo $dom->saveXML();
?>