473,799 Members | 3,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

cdata & innerHTML issues

63 New Member
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.writel n 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.write ln" 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.writel n 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 4588
acoder
16,027 Recognized Expert Moderator MVP
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
6009
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 cdata sections will be echoed an not the element names as in the original example. In the cdata sections of my XML file I have terms like this:
4
8597
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 comments and PI which have purposely been left out). It isn't however the case when it comes to CDATA handling. I have the following code: text="""<html><head> <title>Document</title> </head>
2
11535
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 understand how to add the new names to the list. I have 3 questions: 1) How can I search through the table rows to find the rows to be changed or removed?
9
2126
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 and Safari, but in the latest FireFox I get no title or article, but do see the prev and next links and the article number. My HTML and JS simple routine is as follows:
8
4093
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 ∑ http://xahlee.org/
2
17557
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 html, I can put this in a CDATA section with PHP, but how do I retrieve that information with Javascript and put the HTML in a div ? thanx, Pugi!
6
6863
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 the data contains reserved chars like "&"). Currently, I perform a simple search-and-replace to strip out the CDATA tags before outputting the document. It works but it's not as elegant or reliable as I would wish. Is there a better way of...
0
7192
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 the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one page basically. So how can a person deep link to something that is on one page? This question...
7
5272
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 spitting back out that's giving me issues. The fact that lxml strips all the CDATA stuff off isnt really a big issue either, so long as I can create CDATA blocks later with <>&'s showing up instead of &lt;&gt;&amp; . I've scoured through the lxml docs, but...
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.