473,401 Members | 2,068 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,401 software developers and data experts.

using ajax to get document element from xml file

anfetienne
424 256MB
Hi Everyone,

I am currently learning AJAX using the book "A Beginners Guide" By Steve Holzner and I am confused as to why a piece of code I've just written to test out what is in the book is not working. My code is below for the html page with the ajax script and also the xml document where the data is, could someone let me know where I have gone wrong? Thanks in advance

***html page
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Getting the Document Element</title>
  6. <script type="javascript">
  7. function getDocumentElement()
  8. {
  9. var XMLHttpRequestObject = false;
  10.  
  11.     if (window.XMLHttpRequest){
  12.         XMLHttpRequestObject = new XMLHttpRequest();    
  13.     } else if (window.ActiveXObject) {
  14.         XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
  15.     }
  16.  
  17.     if (XMLHttpRequestObject) {
  18.         XMLHttpRequestObject.open("GET", "party.xml", true);
  19.  
  20.         XMLHttpRequestObject.onreadystatechange = function()
  21.         {
  22.             if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
  23.                 var xmlDocument = XMLHttpRequestObject.responseXML;
  24.                 var documentElement = xmlDocument.documentElement;
  25.                 if(documentElement){
  26.                     document.getElementById("targetDiv").innerHTML = "The document element is &lt;" + documentElement.node + ">.";
  27.                 }
  28.             }
  29.         }
  30.     XMLHttpRequestObject.send(null);
  31.     }
  32. }
  33. </script>
  34. </head>
  35.  
  36. <body>
  37. <h1>Getting the Document Element</h1>
  38.  
  39. <form>
  40. <input type="button" value="Get the document element" onclick="getDocumentElement()" />
  41. </form>
  42. <div id="targetDiv" width =100 height=100>
  43. The result will appear here.
  44. </div>
  45. </body>
  46. </html>
  47.  
  48.  
***xml document
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0">
  2. <!DOCTYPE parties [
  3. <!ELEMENT parties (party*)>
  4. <!ELEMENT party (party_title, party_number, subject, date, people*)>
  5. <!ELEMENT party_title (#PCDATA)>
  6. <!ELEMENT party_number (#PCDATA)>
  7. <!ELEMENT subject (#PCDATA)>
  8. <!ELEMENT date (#PCDATA)>
  9. <!ELEMENT first_name (#PCDATA)>
  10. <!ELEMENT last_name (#PCDATA)>
  11. <!ELEMENT people (person*)>
  12. <!ELEMENT person (first_name,last_name)>
  13. <!ATTLIST party
  14.     type CDATA #IMPLIED>
  15. <!ATTLIST person
  16.     attendance CDATA #IMPLIED>
  17. ]>
  18. <parties>
  19.     <party type="winter">
  20.         <party_title>Snow Day</party_title>
  21.         <party_number>63</party_number>
  22.         <subject>No School Today!</subject>
  23.         <date>22/2/2012</date>
  24.         <people>
  25.             <person attendance="present">
  26.                 <first_name>Andre</first_name>
  27.                 <last_name>Etienne</last_name>
  28.             </person>
  29.             <person attendance="absent">
  30.                 <first_name>Simone</first_name>
  31.                 <last_name>Etienne</last_name>
  32.             </person>
  33.             <person attendance="present">
  34.                 <first_name>Jason</first_name>
  35.                 <last_name>Etienne</last_name>
  36.             </person>
  37.         </people>
  38.     </party>
  39. </parties>
  40.  
Jul 23 '11 #1
4 2306
Dormilich
8,658 Expert Mod 8TB
what property is documentElement.node supposed to be? the only useful DOM property I can imagine is tagName (nodeValue would be null, since it is an element node)
Jul 24 '11 #2
anfetienne
424 256MB
that is what I was thinking but I'm going by this book... I gave it a try but still it doesn't do anything and the innerHTML doesn't change either
Jul 24 '11 #3
anfetienne
424 256MB
It's got me scratching my wig... I even copied and pasted the code that was written in the book
Jul 24 '11 #4
Dormilich
8,658 Expert Mod 8TB
I gave it a try but still it doesn't do anything and the innerHTML doesn't change either
anything in the error console?


I even copied and pasted the code that was written in the book
even books can have errors.
Jul 24 '11 #5

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

Similar topics

0
by: Tor Hovland | last post by:
I'm trying to transform the document element of incoming xml files, however, I'm having trouble with namespace references not appearing correctly. Here's an example input file: <?xml...
1
by: Andy Fish | last post by:
Hi, I'm using XML DOM in Java and I have a function like this Element makeSomeXml(Document doc) {..} This returns an Element owned by (but not appended to) the specified document. Now,...
4
by: BizTalk Benjamin | last post by:
Hi, I have an XmlDocument loaded from a memory stream. I set the document element prefix in this way XmlElement e = xDoc.DocumentElement; e.Prefix = "abc" When i simply write the document...
17
by: pbd22 | last post by:
hi. i keep getting this error. as i understand it, my xml isn't formatted correctly. the online errata suggests the standard formatting to solve this problem: element (tab) (tab) element
5
by: Martin | last post by:
Hello NG, I've been doing some AJAX for a few weeks now. The basics worked fine so far, but now I've got the following problem which I can't solve: With AJAX you typically update/replace only...
3
by: noballack | last post by:
I've got a problem, I'm working with Ajax in a web with a form with a list of checkbox added to the form via an Ajax.Updater method. These added checkboxs are not been sended by the form if I use...
1
by: MORALBAROMETER | last post by:
Hi all, I want to update MULTIPLE elements of an HTML page using Ajax. for this reason i my response is an xml document. I want to use XSL at the client side to update these elements. How can i...
1
by: conspireagainst | last post by:
Is there any possible way (I'm using prototype framework) to glean what the name of the container element to be updated (using Ajax.Updater) is? I have appended at the bottom of prototype.js a...
5
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
5
anfetienne
by: anfetienne | last post by:
hi, I am using ajax to load external pages into a div layer... my reason for this is when in a certain section of the site the transition is smooth with no white flash. my problem is that when...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
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.