473,386 Members | 1,693 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,386 software developers and data experts.

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 2595
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
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
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
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
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
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
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
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
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
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
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.