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 164 | Next

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

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

No
problem in the second line because you??™ve now properly encoded the ampersand. But in the
final example, you??™re trying to use the HTML entity for the copyright symbol (©), which
ultimately fails in the XML example. To fix it, simply encode the ampersand in the entity itself:
© Smith & Smith
The ampersand entity gets turned into an ampersand upon retrieval and then the copyright
entity gets converted into a copyright symbol upon insertion into the HTML DOM.
Let??™s take a look at the book example from before and see how you can approach it differently.
The XML will need to contain the encoded HTML within each node:


<h2>The Long Road</h2>
<p class="author">Jonah Smith</p>
<p>Smith details his battles from the mailroom to the CEO of Megacorp<a
/p>


<h2>Time: fact or fiction</h2>
<p class="author">Dr. Michelle Doe</b></p>
<p>Is time just a figment of our imagination? Dr. Doe, a physicist anda
Nobel prize ...</p>


CHAPTER 5 n AJAX AND DATA EXCHANGE 111
When you loop through, you can now simplify things greatly:
for(var i=0;i{
// create the book container
book = document.createElement('div');
book.className = 'book';
book.id = books[i].getAttribute('id');
book.


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