XML on a Mac doesn't handle <![CDATA[]]>?

Ken Ray kray at sonsothunder.com
Tue Apr 18 11:55:39 EDT 2006


On 4/18/06 10:35 AM, "Peter T. Evensen" <pevensen at siboneylg.com> wrote:

> I have a XML file that contains the following:
> 
> <Text>Gelatin desserts, such as JELL-O<![CDATA[<sup>®</sup>]]>, will
> not become firm and jelly-like if prepared with fresh pineapple.  However,
> this problem can be solved by using canned pineapple instead.  Using your
> knowledge of enzymes, explain these two different reactions.</Text>
> 
> I use the <![CDATA[]]> to encapsulate entities that the Rev XML library
> doesn't support, and to include the HTML superscript.  This works fine on
> Windows, but on the Mac, revXMLNodeContents only returns "Gelatin desserts,
> such as JELL-O"
> 
> Any suggestions?  Is this a bug in the Mac XML library?

Yes, it is AFAIK - if you have *just* CDATA, you should be able to read it,
but if you have both text contents of a node AND CDATA, the CDATA is not
read. It's odd that it works on Windows, though, and not Mac since I thought
it used the same library code under the hood.

IF you are interested in an alternative solution, the STS XML Library can
parse it out for you. Although it currently doesn't handle this kind of
embedded CDATA with stsXML_GetNodeData (the equivalent of
revXMLNodeContents), it CAN get the values independently for each TEXT and
CDATA node because it can address and retrieve them separately. For example,
if you had this as your "tree" that was parsed:

<?xml version="1.0"?>
<Text>Gelatin desserts, such as JELL-O<![CDATA[<sup>®</sup>]]>, will
not become firm and jelly-like if prepared with fresh pineapple.  However,
this problem can be solved by using canned pineapple instead.  Using your
knowledge of enzymes, explain these two different reactions.</Text>

after parsing, the STS XML Library would assign node ID numbers to the
different kind of nodes, like this (this uses the stsXML_dump utility
function in the library):

[1.0:DOC][>> 1.1]
[>> 1.2]
[1.1:XDEC]<?xml version="1.0"?>
[1.2:ELEM]<Text>[>> 1.3][>> 1.4][>> 1.5]</Text>
[1.3:TEXT]Gelatin desserts, such as JELL-O
[1.4:CDAT]<![CDATA[<sup>®</sup>]]>
[1.5:TEXT], will 
not become firm and jelly-like if prepared with fresh pineapple.  However,
this problem can be solved by using canned pineapple instead.  Using your
knowledge of enzymes, explain these two different reactions.

So Node 1.3 and 1.5 are the surrounding TEXT nodes, and node 1.4 is the
CDATA node. So you could get assemble the data this way:

put stsXML_GetText("1.3") & stsXML_GetCDATA("1.4") & \
   stsXML_GetText(1.5) into tContents

Which would set tContents to:

Gelatin desserts, such as JELL-O<sup>®</sup>, will
not become firm and jelly-like if prepared with fresh pineapple.  However,
this problem can be solved by using canned pineapple instead.  Using your
knowledge of enzymes, explain these two different reactions.

Knowing this kind of embedded CDATA is a possiblity, I will be retrofitting
the STS XML Library to handle this with stsXML_GetNodeData, but at least you
have a solution if you need one right away, and my library works
side-by-side with the Rev DLL so you can pick and choose when to use each
one.

More info if you're interested at:

  http://www.sonsothunder.com/products/xmllib/xmllib.htm


Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com




More information about the use-livecode mailing list