473,396 Members | 1,995 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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

Jul 17 '05 #1
1 2312
Jean-Marc Molina a écrit/wrote :
echo ($dom_doc->html_dump_mem ());


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

--
Jean-Marc.

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: gene.ellis | last post by:
Hello everyone, I am really having a lot of trouble understanding the DOM and I doing something quite basic. I need to the DOM (in PHP 5) to modify an XML file. For example the XML basically...
1
by: Juliano Freitas | last post by:
Hello! i'm usin a DOM module to process a xml file. I'm having problems with the appenChild function. Why in my example below i can't append the child 'ele' into the swdb. <swdb>...
4
by: Juliano Freitas | last post by:
How can i get the text between the <teste> tags?? >>> xml = """<root><teste> texto </teste></root>""" >>> from xml.dom import minidom >>> document = minidom.parseString(xml) >>> document...
3
by: robert.oschler | last post by:
I have an AJAX driven page where I dynamically add rows to a known table on the page, based on the return document from the AJAX call, using DOM node methods (except for a small snippet of code,...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
8
by: bennett.matthew | last post by:
Hello all, This is probably an elementary (no pun intended) question, but I've spent all afternoon on it and it's driving me crazy. I have a function which dynamically adds to a table. It...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: Maksim Kasimov | last post by:
Hi, i'm faced with such a problem when i use xml.dom.minidom: to append all child nodes from "doc" in "_requ" to "doc" in "_resp", i do the following: _requ =...
4
by: paragpdoke | last post by:
Hello Perl Experts. I am new to perl and seek help with some XML stuff. My XML document is nested a few levels deep...so I want to use xpath to find the exact element to work with. Then I wish to:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.