PDA

View Full Version : XML CDATA sections


darelf
07-02-2002, 05:20 PM
Here's what I want to accomplish:
Have descriptive text embedded in the xml document with html tags, i.e. This is in bold.
if I do this:

from xml.dom.minidom import *

d = parse('myfile.xml')

e = d.getElementsByTagName('desc')
x = e[0].firstChild

The value of the text node in x ends up like this:

&ltb>This is in bold.&lt/b>

Which would be ok, but how do I turn it back? Or should I worry? I'll be passing the string to a Qt RichText widget, which is expecting "html"-type input.

Or should I be using a different method of storing this stuff altogether?

darelf
07-02-2002, 05:32 PM
Oh Total brain barf.....

a screwed up data file got me on this one, guys.. sorry...
It wasn't wrapped in a CDATA section and was causing my problem....

my bad...

Strike
07-04-2002, 04:00 AM
bad darelf, from foo import * is bad Python karma

For this case, I'd do

import xml.dom.minidom as minidom
and then call
minidom.parse
instead of just "parse", which you don't really know where that sort of thing comes from.

:) sorry, I had to

darelf
07-04-2002, 12:52 PM
Of course. I was just dumping for you what I was entering on the python interactive shell. It easy when you're only concerned with a single library and how it's going to spit out results.

Of course, since I'm self-taught in virtually all the "newer" languages (Python, Tcl, C++) I probably *do* have some bad habits.

Strike
07-04-2002, 03:49 PM
Ah yes, in the interpreter I do from foo import * simply because it's easy and I don't really have to worry about scope issues. But, now you know what I would recommend :)