This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem getting Javascript to display XML data

 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
XML beginner problem:
I visited www.xml101.com as suggested in another thread and I was doing a tutorial.
When I tried to get javascript to display data on my own computer by copying an XML file and the HTML file from the site to a single folder on my computer they wouldn't work. The HTML file doesn't seem to get the data.
I have PWS activated and IE 5.5.
What else must I do to get this working?

Thanks in advance for any help.
Terry
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I got another example to work by using a different way of embedding the XML I found it a this site:
www.inquiry.com/techtips/dhtml_pro/10min/10min0501/td051501-1.asp

I still don't know why the other way works on their site and not on my PC though

[This message has been edited by Terence Doyle (edited August 07, 2001).]
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Terence
Can you post the code so we can take a look at it. I'n new to xml myself but, fairly proficient with javascript and html.

Dave
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.
Heres the xml document called 'note.xml' :

And here's the html document:



[This message has been edited by Terence Doyle (edited August 07, 2001).]
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to run your code. Its working fine. I can't think of any reason why isn't it working on your machine?
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I'll have to do some other tests to see what's up.
Terry
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case you are still not able to solve your problem try accessing the XML elements by name. Addressing elements by number is not the preferred way to extract XML elements from an XML document. Using names is a better way.
Try to replace the following JavaScript lines that reads XML data from an XML document and writes the XML data into (waiting) HTML elements.

your code
 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that you notice that the text element of a node is the child node of the element.
To extract the text (AFriend) from an element like this: <from>AFriend</from>, you must address the child node
like this: getElementsByTagName("from").item(0).text,
and not like this: getElementsByTagName("from").text
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Thanks for the idea Parmeet but that doesn't work either. I get an error message
"Line 7: An Object is required"
It's as if the span objects weren't defined.

Terry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic