473,503 Members | 2,238 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Writing CDATA in XML output ?

I'm utterly confounded, and can only find info on parsing CDATA _from_ an XML
file, not _writing_ CDATA in XML formatted output.
---------------------------------
What I am currently generating :
<events>
<day thedate="15/10/2004" text1="var1" text2="var2" /></day>
. . .
</events>
---------------------------------
What I need to generate (word wrap aside) :
<events>
<day thedate="15/10/2004" text1="var1" text2="var2" /><![CDATA[
$details_field_here ]]></day>
. . .
</events>
---------------------------------
I can't figure out how to take the MySQL field containing HTML and insert it
into a CDATA segment as required.
---------------------------------

The code I have so far :

$root = $doc->add_root("events");
while (list($thedate, $var1, $var2, $details) = mysql_fetch_row($result)) {
$record = $root->new_child("day", "");
$record->set_attribute("thedate", $thedate);
$record->set_attribute("text1", $var1);
$record->set_attribute("text2", $var2);
// Stuck here, trying to insert $details CDATA
}

I've seen the short manual page about create_cdata_section, but nothing that's
actually helpful. I must be missing something in all my Googling and
manual-reading, but I'm stumped.

Any and all advice will be greatly appreciated. TIA !

Jul 17 '05 #1
2 2604
us****@isotopeREEMOOVEmedia.com wrote:
I've seen the short manual page about create_cdata_section, but nothing that's
actually helpful. I must be missing something in all my Googling and
manual-reading, but I'm stumped.

Any and all advice will be greatly appreciated. TIA !


Untested, but this should do it:

....
$record = $root->new_child("day", "");
$record->set_attribute("thedate", $thedate);
$record->set_attribute("text1", $var1);
$record->set_attribute("text2", $var2);
// Add $details CDATA
$cdata = $doc->create_cdata_section($details);
$record->append_child($cdata);
....
JW

Jul 17 '05 #2
On Mon, 17 Jan 2005 10:16:58 +0100, Janwillem Borleffs <jw@jwscripts.com> wrote:
us****@isotopeREEMOOVEmedia.com wrote:
I've seen the short manual page about create_cdata_section, but nothing that's
actually helpful. I must be missing something in all my Googling and
manual-reading, but I'm stumped.

Any and all advice will be greatly appreciated. TIA !


Untested, but this should do it:

...
$record = $root->new_child("day", "");
$record->set_attribute("thedate", $thedate);
$record->set_attribute("text1", $var1);
$record->set_attribute("text2", $var2);
// Add $details CDATA
$cdata = $doc->create_cdata_section($details);
$record->append_child($cdata);
...
JW


Thanks, JW ! That's exactly right. I didn't realize that append_child was
necessary here.

This is a huge help -- thanks so much.

Jul 17 '05 #3

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

Similar topics

0
1985
by: Isaac Councill | last post by:
Hello, This seems like a newbie question, but I couldn't find the answer on google. I've been using xsl to transform rdf files into runnable programs in another (non-markup) language. It's...
0
2072
by: Dimitre Novatchev | last post by:
You seem to be unaware of the xslt processing which uses the built-in rules in the absence of templates that match some selected node. http://www.w3.org/TR/xslt#built-in-rule According to the...
0
419
by: Yasutaka Ito | last post by:
Hi folks! I have a DataSet, which I'm writing into XML using the DataSet.WriteXML() method. Now, I want to write the cell's data/text as CDATA, when it is written into an XML. For example, I...
1
3888
by: Tomas Vera | last post by:
Hello All, I'm having trouble writing some special characters to an XML file. I need to output a XMLSS formatted file to be read by Excel. In some cells there will be some text that contains...
1
3388
by: chris | last post by:
Confused somewhat xml newbie. I'm trying to output xml with a CDATA section, using saxutils.XMLGenerator, but the output contains escaped '<' and '>' and '&' from the CDATA element. Shouldn't it...
4
2242
by: troppfigo | last post by:
I have this example of xml <?xml version="1.0"?> <xml> <!]> </xml> I want to extract the contained data from <body> tag using an xslt transformation. I want to obtain this
2
5225
by: Steveino | last post by:
Hello, Just wondering if anyone could shed any light on this, it's probably me just being silly... I have a dataset that I've used to create an XmlDataDocument, in order to apply XSL. The XSL...
1
2578
by: RolfK | last post by:
Hello Experts, I have a small problem with copy of CDATA sections. (I'm using XSLT2.0 ) My output target is defined as txt. In my xml source is a CDATA section to be put as it is into the...
6
4776
by: dkyadav80 | last post by:
Hi sir, I'm new about xml, javascript. I have two selection field(html) first is city and second is state. the city and state values should be store in xml file. when user select city then all...
0
7207
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
7093
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
7291
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
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
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...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.