Hello,
I'm trying to generate a RSS newsfeed using the DOM XML functions, but you
already know that if you read my previous post .
I'm able to create rss, channel and title elements but not a link element.
The following code sample doesn't generated
<link>http://www.websitetitle.com</link> but <link> like if the DOM XML
forgot to close the element :
<?php
$link_el = $dom_doc->create_element ('link');
$link_el = $channel_el->append_child ($link_el);
$link_el->set_content ('http://www.websitetitle.com');
?>
Then I got some crazy idea. I thought that maybe DOM XML was thinking the
link element I created was a specially element, not an enclosed one, like in
XHTML for example :
<link rel="stylesheet" type="text/css" href="styles.css" />
Crazy crazy because I don't see why DOM XML would handle my elements as HTML
elements... But then I tried with a meta tag, and guess what... It also
doesn't work ! It works with enclosed elements, tags, like title, head,
html, body or unknown ones like channel or item. But it doesn't work with
link, meta and input elements !
And I have no clue why it handles these elements as special elements...
Here is the full script :
<?php
header ('content-type: text/xml');
echo ('<?xml version="1.0" encoding="ISO-8859-15"?>');
$dom_doc = domxml_new_doc ('1.0');
$rss_el = $dom_doc->create_element ('rss');
$rss_el->set_attribute ('version', '2.0');
$rss_el = $dom_doc->append_child ($rss_el);
$channel_el = $dom_doc->create_element ('channel');
$channel_el = $rss_el->append_child ($channel_el);
$title_el = $dom_doc->create_element ('title');
$title_el = $channel_el->append_child ($title_el);
$title_el->set_content ('Website title - News');
$link_el = $dom_doc->create_element ('link');
$link_el = $channel_el->append_child ($link_el);
$link_el->set_content ('http://www.websitetitle.com');
echo ($dom_doc->html_dump_mem ());
?>
If you rename 'link' to 'link2', it works !
JM