[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: CDATA sections in W3C XML Infoset

  • From: Gavin Thomas Nicol <gtn@e...>
  • To: xml-dev@l...
  • Date: Thu, 29 Mar 2001 05:34:30 -0500

getelementsbytagname cdata
> After I get the tree, I call normalize() on it. Suppose my processing
> is to count people whose first name is "Karl", in a document like
>
> <people><person><first>Karl</first><last>Käfer</last></person></people>
>
> Then I'd do
>
>   karls = 0
>   root.normalize()
>   for person in root.getElementsByTagName("person"):
>       first = person.getElementsByTagName("first")[0]
>       for n in first.childNodes:
>           if n.nodeType == Node.TEXT_NODE and n.data == "Karl":
>               break
>       else:
>           continue
>       karl += 1
>
> Now, if there are CDATA sections in there, this algorithm will break:
> the string Karl could still be split across several nodes.

As I just noted, normalize() shouldn't be guaranteed to succeed.
Even so, the example above is simplistic... if I choose to, I
can break the code above any number of ways.

CDATA sections are usually used to simplify the markup of
largish chunks of text that contain markup characters, so you'd
be less likely to find them in the above than you'd probably
than entity references.

  <?xml version="1.0" encoding="US-ASCII"?>
  <!DOCTYPE people [
  <!ENTITY ad "&#x00E4;">
  ]>
  <people>
    <person>
      <first>Karl</first>
      <last>K&ad;fer</last>
    </person>
  </people>

At the end of the day, almost every application has some number
of constraints on the actual use of XML. If that is not the case,
it's better to normalize, then process.



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.