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
create an xml tag with colon using php
Moderator: General Moderators
http://www.feedforall.com/mediarss.htm
Take a look at http://de2.php.net/manual/en/function.d ... espace.phpDeclaration: 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">
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
<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
No, sorry, I can't. Since switching to php 5 I haven't used domxml.madhu wrote:Can you please tell me how to define namespace??
But
volka wrote:Take a look at http://de2.php.net/manual/en/function.d ... espace.php
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).
You have to declare the namespace first, i.e. add the attribute xmlns:media with the url to the definition (xmlns, xml namespace).
http://de2.php.net/manual/en/function.d ... espace.php probably would have done this for you.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/">
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();
?>