How to geneate media:content xml using php












0















i facing few issue's i don't know how to resolve it



i want to write following rss feed using php and mysql:



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<item>
<title>Here is the title</title>
<link>http://example.com</link>
<media:content medium="image" url="http://example.com/image.jpg"></media:content>
<media:content medium="video" url="http://example.com/video.mp4"></media:content>
</item>
</channel>
</rss>


here is my code in php:



$db = new Db();

$result = $db->select("select * from column");

$xml = new SimpleXMLElement('<channel/>');


for ($i = 0; $i < count($result); $i++) {

$title = $result[$i]title
$link = $result[$i]['link'];
$image = $result[$i]['image'];
$video = $result[$i]['video'];

$item = $xml->addChild('item');

$item->title = $title
$item->link = $link
$item->image = ?? ;
$item->video = ?? ;

}
Header('Content-type: text/xml');
print($xml->asXML());


just don't know how to set image and video because there tags are different like media:content and url of both image and video tags. please let me know



thanks










share|improve this question























  • Namespace prefix, such as media in your XML, need to be declared somewhere (something along this line: xmlns:media="foo"). As posted the XML is not well-formed. Now, on which element do you want the ns prefix declaration to be?

    – har07
    May 4 '16 at 22:32
















0















i facing few issue's i don't know how to resolve it



i want to write following rss feed using php and mysql:



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<item>
<title>Here is the title</title>
<link>http://example.com</link>
<media:content medium="image" url="http://example.com/image.jpg"></media:content>
<media:content medium="video" url="http://example.com/video.mp4"></media:content>
</item>
</channel>
</rss>


here is my code in php:



$db = new Db();

$result = $db->select("select * from column");

$xml = new SimpleXMLElement('<channel/>');


for ($i = 0; $i < count($result); $i++) {

$title = $result[$i]title
$link = $result[$i]['link'];
$image = $result[$i]['image'];
$video = $result[$i]['video'];

$item = $xml->addChild('item');

$item->title = $title
$item->link = $link
$item->image = ?? ;
$item->video = ?? ;

}
Header('Content-type: text/xml');
print($xml->asXML());


just don't know how to set image and video because there tags are different like media:content and url of both image and video tags. please let me know



thanks










share|improve this question























  • Namespace prefix, such as media in your XML, need to be declared somewhere (something along this line: xmlns:media="foo"). As posted the XML is not well-formed. Now, on which element do you want the ns prefix declaration to be?

    – har07
    May 4 '16 at 22:32














0












0








0


1






i facing few issue's i don't know how to resolve it



i want to write following rss feed using php and mysql:



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<item>
<title>Here is the title</title>
<link>http://example.com</link>
<media:content medium="image" url="http://example.com/image.jpg"></media:content>
<media:content medium="video" url="http://example.com/video.mp4"></media:content>
</item>
</channel>
</rss>


here is my code in php:



$db = new Db();

$result = $db->select("select * from column");

$xml = new SimpleXMLElement('<channel/>');


for ($i = 0; $i < count($result); $i++) {

$title = $result[$i]title
$link = $result[$i]['link'];
$image = $result[$i]['image'];
$video = $result[$i]['video'];

$item = $xml->addChild('item');

$item->title = $title
$item->link = $link
$item->image = ?? ;
$item->video = ?? ;

}
Header('Content-type: text/xml');
print($xml->asXML());


just don't know how to set image and video because there tags are different like media:content and url of both image and video tags. please let me know



thanks










share|improve this question














i facing few issue's i don't know how to resolve it



i want to write following rss feed using php and mysql:



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<item>
<title>Here is the title</title>
<link>http://example.com</link>
<media:content medium="image" url="http://example.com/image.jpg"></media:content>
<media:content medium="video" url="http://example.com/video.mp4"></media:content>
</item>
</channel>
</rss>


here is my code in php:



$db = new Db();

$result = $db->select("select * from column");

$xml = new SimpleXMLElement('<channel/>');


for ($i = 0; $i < count($result); $i++) {

$title = $result[$i]title
$link = $result[$i]['link'];
$image = $result[$i]['image'];
$video = $result[$i]['video'];

$item = $xml->addChild('item');

$item->title = $title
$item->link = $link
$item->image = ?? ;
$item->video = ?? ;

}
Header('Content-type: text/xml');
print($xml->asXML());


just don't know how to set image and video because there tags are different like media:content and url of both image and video tags. please let me know



thanks







php xml






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 4 '16 at 22:12









MK DEVMK DEV

499




499













  • Namespace prefix, such as media in your XML, need to be declared somewhere (something along this line: xmlns:media="foo"). As posted the XML is not well-formed. Now, on which element do you want the ns prefix declaration to be?

    – har07
    May 4 '16 at 22:32



















  • Namespace prefix, such as media in your XML, need to be declared somewhere (something along this line: xmlns:media="foo"). As posted the XML is not well-formed. Now, on which element do you want the ns prefix declaration to be?

    – har07
    May 4 '16 at 22:32

















Namespace prefix, such as media in your XML, need to be declared somewhere (something along this line: xmlns:media="foo"). As posted the XML is not well-formed. Now, on which element do you want the ns prefix declaration to be?

– har07
May 4 '16 at 22:32





Namespace prefix, such as media in your XML, need to be declared somewhere (something along this line: xmlns:media="foo"). As posted the XML is not well-formed. Now, on which element do you want the ns prefix declaration to be?

– har07
May 4 '16 at 22:32












1 Answer
1






active

oldest

votes


















2














You can not do that. Your XML is not valid. Prefixed tags must have a declared NameSpace URI, in your case 'http://search.yahoo.com/mrss/':



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
(...)
</rss>


You can use ->addChild to create namespaced elements:



$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel/>
</rss>');

(...)

$item = $xml->channel->addChild('item');

$item->title = $title;
$item->link = $link;

/* Add <media:image>: */
$node = $item->addChild( 'image', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $image );

/* Add <media:video>: */
$node = $item->addChild( 'video', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $video );


Result:



<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Your Title</title>
<link>http://www.somelink.it/</link>
<media:image url="http://www.image.com/"/>
<media:video url="http://www.video.com/"/>
</item>
</channel>
</rss>





share|improve this answer
























  • you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

    – MK DEV
    May 5 '16 at 9:02








  • 1





    I don't understand. Please clarify

    – fusion3k
    May 5 '16 at 9:03











  • because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

    – MK DEV
    May 5 '16 at 9:09











  • you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

    – MK DEV
    May 5 '16 at 9:11






  • 1





    In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

    – fusion3k
    May 5 '16 at 9:16













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37038954%2fhow-to-geneate-mediacontent-xml-using-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














You can not do that. Your XML is not valid. Prefixed tags must have a declared NameSpace URI, in your case 'http://search.yahoo.com/mrss/':



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
(...)
</rss>


You can use ->addChild to create namespaced elements:



$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel/>
</rss>');

(...)

$item = $xml->channel->addChild('item');

$item->title = $title;
$item->link = $link;

/* Add <media:image>: */
$node = $item->addChild( 'image', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $image );

/* Add <media:video>: */
$node = $item->addChild( 'video', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $video );


Result:



<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Your Title</title>
<link>http://www.somelink.it/</link>
<media:image url="http://www.image.com/"/>
<media:video url="http://www.video.com/"/>
</item>
</channel>
</rss>





share|improve this answer
























  • you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

    – MK DEV
    May 5 '16 at 9:02








  • 1





    I don't understand. Please clarify

    – fusion3k
    May 5 '16 at 9:03











  • because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

    – MK DEV
    May 5 '16 at 9:09











  • you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

    – MK DEV
    May 5 '16 at 9:11






  • 1





    In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

    – fusion3k
    May 5 '16 at 9:16


















2














You can not do that. Your XML is not valid. Prefixed tags must have a declared NameSpace URI, in your case 'http://search.yahoo.com/mrss/':



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
(...)
</rss>


You can use ->addChild to create namespaced elements:



$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel/>
</rss>');

(...)

$item = $xml->channel->addChild('item');

$item->title = $title;
$item->link = $link;

/* Add <media:image>: */
$node = $item->addChild( 'image', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $image );

/* Add <media:video>: */
$node = $item->addChild( 'video', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $video );


Result:



<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Your Title</title>
<link>http://www.somelink.it/</link>
<media:image url="http://www.image.com/"/>
<media:video url="http://www.video.com/"/>
</item>
</channel>
</rss>





share|improve this answer
























  • you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

    – MK DEV
    May 5 '16 at 9:02








  • 1





    I don't understand. Please clarify

    – fusion3k
    May 5 '16 at 9:03











  • because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

    – MK DEV
    May 5 '16 at 9:09











  • you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

    – MK DEV
    May 5 '16 at 9:11






  • 1





    In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

    – fusion3k
    May 5 '16 at 9:16
















2












2








2







You can not do that. Your XML is not valid. Prefixed tags must have a declared NameSpace URI, in your case 'http://search.yahoo.com/mrss/':



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
(...)
</rss>


You can use ->addChild to create namespaced elements:



$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel/>
</rss>');

(...)

$item = $xml->channel->addChild('item');

$item->title = $title;
$item->link = $link;

/* Add <media:image>: */
$node = $item->addChild( 'image', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $image );

/* Add <media:video>: */
$node = $item->addChild( 'video', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $video );


Result:



<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Your Title</title>
<link>http://www.somelink.it/</link>
<media:image url="http://www.image.com/"/>
<media:video url="http://www.video.com/"/>
</item>
</channel>
</rss>





share|improve this answer













You can not do that. Your XML is not valid. Prefixed tags must have a declared NameSpace URI, in your case 'http://search.yahoo.com/mrss/':



<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
(...)
</rss>


You can use ->addChild to create namespaced elements:



$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
<channel/>
</rss>');

(...)

$item = $xml->channel->addChild('item');

$item->title = $title;
$item->link = $link;

/* Add <media:image>: */
$node = $item->addChild( 'image', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $image );

/* Add <media:video>: */
$node = $item->addChild( 'video', Null, 'http://search.yahoo.com/mrss/' );
$node->addAttribute( 'url', $video );


Result:



<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
<channel>
<item>
<title>Your Title</title>
<link>http://www.somelink.it/</link>
<media:image url="http://www.image.com/"/>
<media:video url="http://www.video.com/"/>
</item>
</channel>
</rss>






share|improve this answer












share|improve this answer



share|improve this answer










answered May 4 '16 at 22:44









fusion3kfusion3k

9,83441434




9,83441434













  • you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

    – MK DEV
    May 5 '16 at 9:02








  • 1





    I don't understand. Please clarify

    – fusion3k
    May 5 '16 at 9:03











  • because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

    – MK DEV
    May 5 '16 at 9:09











  • you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

    – MK DEV
    May 5 '16 at 9:11






  • 1





    In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

    – fusion3k
    May 5 '16 at 9:16





















  • you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

    – MK DEV
    May 5 '16 at 9:02








  • 1





    I don't understand. Please clarify

    – fusion3k
    May 5 '16 at 9:03











  • because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

    – MK DEV
    May 5 '16 at 9:09











  • you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

    – MK DEV
    May 5 '16 at 9:11






  • 1





    In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

    – fusion3k
    May 5 '16 at 9:16



















you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

– MK DEV
May 5 '16 at 9:02







you are genius thanks so much, please just let me know last thing my xml image medium in media content tag please can you just clear this out: <media:content medium="image" url="http://www.website.com/image.jpg"></media:content> xml site given to me is link

– MK DEV
May 5 '16 at 9:02






1




1





I don't understand. Please clarify

– fusion3k
May 5 '16 at 9:03





I don't understand. Please clarify

– fusion3k
May 5 '16 at 9:03













because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

– MK DEV
May 5 '16 at 9:09





because as you said media tag which is little bit different in myside must requirement is opening and closing tag of media content like that example <media:content medium="image" url="http://www.website.com/image.jpg"></media:content>

– MK DEV
May 5 '16 at 9:09













you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

– MK DEV
May 5 '16 at 9:11





you example is working fine but it's didn't show the image in rss feed !! link the image is shown in rss !! so in your example rss images is not show i must have show the images in rss as well please help me out there requirement is must opening and close tag of media:content

– MK DEV
May 5 '16 at 9:11




1




1





In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

– fusion3k
May 5 '16 at 9:16







In XML tags w/out node value are self-closed by <tag ... />, not by <tag></tag>. For <media:content> follow above example: $item->addChild( 'content', ... ), then ->addAttribute( 'url', value ). You can add more than one attribute. See here for availble attributes for media:content.

– fusion3k
May 5 '16 at 9:16




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37038954%2fhow-to-geneate-mediacontent-xml-using-php%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

Refactoring coordinates for Minecraft Pi buildings written in Python