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 & SmithThe 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