By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,760 Members | 1,630 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,760 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
> <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.