473,396 Members | 2,039 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.

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 2422
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.