473,241 Members | 1,488 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,241 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 2412
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: tertius | last post by:
Is there a better way to append certain chars in a string with a backslash that the example below? chr = "#$%^&_{}" # special chars to look out for str = "123 45^ & 00 0_" # string to...
6
by: Jonas Meurer | last post by:
hello, my script selects a comment saved as VARCHAR in MySQL and displays it inside an html page. the problem is, that the comment contains several special characters, as mysterious utf-8...
6
by: Horst Gutmann | last post by:
Hi :-) I currently have quite a big problem with minidom and special chars (for example &uuml;) in HTML. Let's say I have following input file:...
0
by: Steffen Gebert | last post by:
Hello, I want to fetch the page via php from a mysql-db, which is called by an emulated filename (mod_rewrite, but that might be unimportant). So I have a file, which is called by guestbook.html...
2
by: Thorsten Viel | last post by:
Hi List, im trying to use special chars with the std::string (like S) but when i cout<< the string the special chars have disappeared. What's wrong here? Thanks in advance
4
by: dutch disCo | last post by:
Hi, I'm trying to use GET method to pass variables through my script files. Unfortunately, when a special char (&, ?, +) is being posted the variable gets trimmed in a very strange way. I'm...
1
by: LellD | last post by:
It seems not unusual for me that I have special chars like < (less than) or > (greater than) in C# comments, especially in <code> sections. For instance, <code> if(a<b) c=3; </code> should be a...
1
by: Robert Dodier | last post by:
Hello, Sorry for asking what must be a FAQ, but I wasn't able to find the answer. I have an XML document fragment which I want to store as a text string. I want a function to convert any XML...
1
by: Ask Josephsen | last post by:
Hi I want to create an image with vertical text, but how do I handle special chars like ""? I'm using php version 4.4.2. This is my code so far: $string = ""; $fh = 6;
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.