innerHTML = books[i].firstChild.data;
// add the entire book node to the document
container.appendChild(book);
}
The bolded code is where you assign the contents of each book node into the container.
You can even super-simplify it by including the entire HTML snippet as an escaped block:
<div class="book" id="id15669">
<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>
</div>
<div class="book" id="id15670">
<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>
</div>
This way, you no longer have to loop through any elements; you can just append the contents
directly into the container:
var doc = transport.responseXML.documentElement; // grabs the root node
var books = doc.getElementsByTagName('book'); // get all song nodes
var container = document.getElementById('books');
container.innerHTML = doc.firstChild.data;
Escaping all that HTML, however, can make things hard to read and difficult to recognize
that the HTML being returned is actually valid.
CDATA Nodes
The alternative to text nodes is CDATA sections.
Pages:
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177