Re: CDATA
Dethe Elza <[email protected]> Tue, 16 Dec 2003 10:54:06 -0800
| Newsgroups | gmane.comp.web.zope.parsed-xml |
|---|---|
| Message-ID | <[email protected]> |
>> My example XML file is shown as below, >> ------------------------------------------------------ >> <?xml version="1.0" standalone="yes"?> >> <![CDATA[Please help me!]]> >> ----------------------------------------------------- > > This is not a well-formed XML document at all. "CDATA" is > not a tag at all. > > You probably want something like this: > > <?xml version="1.0" standalone="yes"?> > <doc>Please help me!</doc> Well, CDATA isn't a tag, but it's legal XML. A better (and well-formed) example might be: <?xml version="1.0" standalone="yes"?> <doc><![CDATA[Please help me!]]></doc> As for answering the initial question, you would parse it the same way you parse any XML document. How you do that depends on what you want to do with it. Do you want to handle XML events during the parse, in which case you would probably use the SAX interface, or do you want to get back a DOM tree and walk that? There are variations (expat vs. SAX, ElementTree instead of DOM) but those are the two major options. In the SAX case you should make sure to define a handler for CDATA events, and in the case of the DOM you would walk the tree normally and look for CDATA nodes (or, depending on the DOM and it's configuration, Text nodes. Some parsers convert the CDATA to text automatically). If this isn't clear, perhaps you can give more information about how you intend to use the XML after it is parsed. HTH --Dethe