[DOM XML] How to append a link element as a child

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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 :


$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 :


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 !


Re: [DOM XML] How to append a link element as a child

Jean-Marc Molina a écrit/wrote :
Quoted text here. Click to load it

Solution : Use the dump_mem method, not the html_dump_mem one.


Site Timeline