473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

cdata & innerHTML issues

I have been able to successfully retrieve data from an xml file, where the data has been massaged a little bit, to create a table to be retrieved and it is displayed via a document.writeln within a javascript file, but now I am going to go completely AJAX & using innerHTML to display the same information to the browser.

First, snippets of the original code that was working with no problem:
XML first:
Expand|Select|Wrap|Line Numbers
  1.           <title>bla bla</title>
  2.             <music id="newepisode">bla bla bla</music>
  3.          <details>
  4.             &lt;TABLE BORDER=0 WIDTH="100%"&gt;
  5.             &lt;th&gt;
  6.             Featured Band
  7.             &lt;/th&gt;
  8.             &lt;tr&gt;
  9.             &lt;td&gt;
  10. something data here...
  11.             &lt;/td&gt;
  12.             &lt;/tr&gt;
  13.             &lt;/table&gt;
  14.             </details>
  15.                     <music>bla bla bla</music>
  16.  
As you can see, the details node builds a simple table and the code to retrieve this data was:

Of course, after the try & catch xmlhttprequest with all the conditionals for the three types of browsers:

Expand|Select|Wrap|Line Numbers
  1. artistdetails = xml_doc.getElementsByTagName("details");
  2.  
Then the code to display it within the browser:
Expand|Select|Wrap|Line Numbers
  1. document.writeln('<div id="divContainer" style="overflow:auto;"> ');
  2. document.writeln('<div id="divContent"> ');
  3. document.writeln('<p class="pscoll">');
  4. <!-- a list of links to click on which would call the following function -->
  5. document.writeln('</p>');
  6. document.writeln('</div>');
  7. document.writeln('</div>');
  8. document.writeln('<div id="extraDetails" class="extraDetails"><span></span></div>');
  9.  
  10. document.writeln('<div id="extraDetails2" class="extraDetails2"><span></span></div>');
  11.  
  12. function myInsertTheDetailsFunction(l)
  13. {
  14.     div = document.getElementById("extraDetails");
  15.     div.innerHTML = "";
  16.     myDetailsArray[l] = artistdetails[l].childNodes[0].nodeValue;
  17.     div.innerHTML = myDetailsArray[l];
  18. }
  19.  
The above code works fine with the "document.writeln" writing the links to populate the extraDetails div, but now that I am changing to AJAX with everything being innerHTML it will not display anything which is being retrieved that has any rich html data. So I am trying to use CDATA as follows:

Expand|Select|Wrap|Line Numbers
  1.         <title>bla bla bla</title>
  2.         <music id="newepisode" ></music>
  3.             <details>
  4.             <![CDATA[<TABLE BORDER=0 WIDTH="100%">
  5.             <th>
  6.             Featured Band
  7.             </th>
  8.             <tr>
  9.             <td>
  10. some data here...
  11.             </td>
  12.             </tr>
  13.             </table>]]>
  14.             </details>
  15.                     <music></music>
  16.  
the code to retrieve is the same:
Expand|Select|Wrap|Line Numbers
  1. artistdetails = xml_doc.getElementsByTagName("details");
  2.  
the code to display the info is slightly altered for the cdata returned:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <!-- a list of links to click on which would call the following function IS NOW POPULATED BY innerHTML -->
  3.  
  4. someVar4FeaturedArtist = artistdetails[k].childNodes[0].data
  5. function myInsertTheDetailsFunction(l)
  6. {
  7.     div = document.getElementById("extraDetails");
  8.     div.innerHTML = "";
  9.     myDetailsArray[l] = artistdetails[l].childNodes[0].nodeValue;
  10.     div.innerHTML = myDetailsArray[l];
  11. }
  12.  
It's as if the document.writeln which wrote the extraDetails allows the innerHTML to function properly.

Why?

The same div is there from the beginning before anything is called or done. If anyone can point me to some examples or tutorials that have examples of retrieving CDATA from XML and then using Javascript to display the contents of the CDATA data, then it would be appreciated greatly.

Thanks in advance
Jul 17 '07 #1
1 4556
acoder
16,027 Expert Mod 8TB
The CDATA section is of node type 4. See this link for more information.
Jan 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
4
by: alainpoint | last post by:
I am experimenting with ElementTree and i came accross some (apparently) weird behaviour. I would expect a piece of XML to be read, parsed and written back without corruption (except for the...
2
by: Mike | last post by:
My page populates a table with a list of names and other information from a JavaScript object. I receive changes (adds, change & delete) to that list, convert it into a JavaScript object. I do...
9
by: Astra | last post by:
Hi everybody Wonder if you could help me out. I created a simple JavaScript routine to enable a user to click backwards and forwards between small news articles. This routine works fine in IE...
8
by: Xah Lee | last post by:
what does it mean when a style tag gives something like the following? <style type="text/css" media="screen,projection">/*<!]>*/</style> is this standard? Xah xah@xahlee.org ∑...
2
by: Pugi! | last post by:
Using AJAX I want to send some information from the server (php-page) as XML to the client. The contents can be very divers so I have to use XML instead of text. On one occasion the contents is...
6
by: =?Utf-8?B?QmlsbEF0V29yaw==?= | last post by:
Hi, I'm defining a report layout using an XML document, plugging data values into fields before outputting the whole doc as an HTML page. I wrap each of the data fields in CDATA section (in case...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
7
by: Silfheed | last post by:
Heyas So first off I know that CDATA is generally hated and just shouldn't be done, but I'm simply required to parse it and spit it back out. Parsing is pretty easy with lxml, but it's the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.