471,578 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

XML? Does all node contents require HTML special chars (ie. > = >)

Hi,

I am currently writing a simple PHP program that uses an XML file to
output rows for a 'Whats New' page. Once written, I will only require
updating the XML file and any pages that use the XML file will get
their row content from there. The rows may look some thing similar to
this:

- Added <a>mailing list</a> functionality to <a>homepage</a>
- Competition winners announced, click <a>here</a>
- Guidance documents now available - <a>French</a>, <a>German</a> and
<a>Spanish</a>

(obviously, the link tags (<a>) would be in full with href (<a
href="...">) attribute but for the sake of space and simplicity I have
presented them as they are above)

As you can see, they all differ in where links may be for each row. As
a result, I figured that the best solution is to contain the HTML
within the XML nodes:

<?xml version="1.0" encoding="iso-8859-1"?>
<whatsnew>
<item date="2005-08-08">Added <a>mailing list</a> functionality to
<a>homepage</a><item>
<item date="2005-08-05">Competition winners announced, click
<a>here</a></item>
<item date="2005-08-05">Guidance documents now available -
<a>French</a>, <a>German</a> and <a>Spanish</a></item>
</whatsnew>

The PHP for outputing this is:

$xmldoc = domxml_open_file('whatsnew.xml',
DOMXML_LOAD_DONT_KEEP_BLANKS);
$node = $xmldoc->document_element();
if ($xmldoc->has_child_nodes()) {
$node = $node->first_child();
$endwhile = false;
while ($endwhile != true) {
echo $node->get_content() . "<br />";
if ($node->next_sibling()) {
$node = $node->next_sibling();
}else{
$endwhile = true;
}
}
}

This seemed perfect until I realised that when I output them, it didnt
display the HTML tags inside the <item> nodes. So instead I would get
something like:

- Added mailing list functionality to homepage
- Competition winners announced, click here
- Guidance documents now available - French, German and Spanish

(note the links missing)

I understood why this so converted the node content to:

<item date="2005-08-08">Added &lt;a&gt;mailing list&lt;/a&gt;
functionality to &lt;a&gt;homepage&lt;/a&gt;<item>

This worked a treat but I was kinda hoping that I could keep the html
tags intact when in the <item> nodes as it is easier, at a glance, to
recognise the HTML code within the nodes. XML validator doesnt seem to
mind when there is raw HTML (<a> not &lt;a&gt;) inside nodes so is it
possible to change the PHP '$node->get_contents' to something that will
preserve the HTML tags as they are and display them on screen?

If not, I will have to change all the HTML tags to HTML special
characters but this will be quite a job.

Any help would be great, thanks

Burnsy

Aug 11 '05 #1
2 2304
On 2005-08-11, bi******@yahoo.co.uk <bi******@yahoo.co.uk> wrote:
This worked a treat but I was kinda hoping that I could keep the html
tags intact when in the <item> nodes as it is easier, at a glance, to
recognise the HTML code within the nodes. XML validator doesnt seem to
mind when there is raw HTML (<a> not &lt;a&gt;) inside nodes so is it
possible to change the PHP '$node->get_contents' to something that will
preserve the HTML tags as they are and display them on screen?


Things to look up:
<attribute name='content'>
<![CDATA[
<a href="http://example.com">there you go</a>
]]>
</attribute>


<xsl:value-of select="$content" disable-output-escaping="yes"/>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Aug 11 '05 #2
> <xsl:value-of select="$content" disable-output-escaping="yes"/*>

Would I be right in saying that this is XSLT? I dont really have a
great deal of knowledge in this. Is it possible to use this with PHP
XMLDOM doing the output? If so, how would I embed this into my code?
Ideally, can it be done with XMLDOM alone? Cheers

Burnsy

Aug 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by tertius | last post: by
6 posts views Thread by Jonas Meurer | last post: by
6 posts views Thread by Horst Gutmann | last post: by
reply views Thread by Steffen Gebert | last post: by
2 posts views Thread by Thorsten Viel | last post: by
1 post views Thread by LellD | last post: by
1 post views Thread by Ask Josephsen | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

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.