SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 166 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"

The World Wide Web Consortium (W3C)
specification (http://www.w3.org/TR/2004/REC-xml-20040204/#sec-cdata-sect) describes
them really well:
CHAPTER 5 n AJAX AND DATA EXCHANGE 112
CDATA sections MAY occur anywhere character data might occur; they are used to
escape blocks of text containing characters which would otherwise be recognized as
markup. CDATA sections begin with the string "string "]]>".
CDATA sections give you a lot of flexibility and can remove much of the worry about
encoding, which makes it easier to work with HTML content:
Smith & Smith]]>
Retrieving the content from a CDATA section works exactly like retrieving it from a text
node. The book example would get encoded as follows:

The Long Road


Jonah Smith


Smith details his battles from the mailroom to the CEO of Megacorp




Time: fact or fiction


Dr. Michelle Doe


Is time just a figment of our imagination? Dr. Doe, a physicist anda
Nobel prize ...



]]>

Already, the HTML is much easier to understand. Embedding that entire snippet is handled
exactly the same as it was before:
var doc = transport.responseXML.documentElement; // grabs the root node
var books = doc.


Pages:
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178