473,385 Members | 1,834 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,385 software developers and data experts.

nodeValue is 'null' - why?!

Hi Guys,

I'm a newbie to XML so I tried to create my first "hello-world". Actually I already failed here. The Code returns 'null'. I'm aware of the white-space bug and I actually think, that I avoided it. So have a look:

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
  4. <head>
  5.     <title>JavaScript und XML</title>
  6. <script type="text/javascript">
  7. //<![CDATA[
  8. var loadXML = function(xmlDoc)
  9. {
  10.     if (window.ActiveXObject)
  11.     {
  12.         xml = new ActiveXObject("Microsoft.XMLDOM");
  13.         xml.async = false;
  14.         xml.load(xmlDoc);
  15.         parseXML();
  16.     }
  17.     else if (document.implementation && document.implementation.createDocument)
  18.     {
  19.         xml = document.implementation.createDocument("","",null);
  20.         xml.async = false;
  21.         xml.onload = parseXML;
  22.         xml.load(xmlDoc);
  23.     }
  24.     else
  25.     {
  26.         alert("Can't open XML-Page.");
  27.     }
  28. }
  29. window.onload = function()
  30. {
  31.     loadXML("blumen.xml");
  32. }
  33.  
  34. var parseXML = function()
  35. {
  36.     var x=xml.documentElement.getElementsByTagName('name')[0].nodeValue;
  37.     alert(x);
  38.  
  39. }
  40.  
  41. //]]>
  42. </script>
  43.  
  44. </head>
  45. <body>
  46.  
  47.  
  48. </body>
  49. </html>
  50.  
and here's the XML-file "blumen.xml":

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>\
  2. <root>\
  3.     <blume>\
  4.         <name>Rose</name>\
  5.         <preis>1.10</preis>\
  6.     </blume>\
  7.     <blume>\
  8.         <name>Tulpe</name>\
  9.         <preis>0.90</preis>\
  10.     </blume>\
  11. </root>
What am I doing wrong?!

Thanks for ur help!
Aug 27 '07 #1
2 8193
phvfl
173 Expert 100+
Hi,

Does the script have access to open the file? If the page is running as a local page, ie not through http protocol then is would not be able to access the file, if this is through http then it should be able to access the file and I will keep looking at it.

Also, just noticed that there seems to be a trailing slash "\" at the end of each line, including the declaration, is this the case or is this a result of copying the file as this could also cause an issue.
Aug 30 '07 #2
markrawlingson
346 Expert 100+
The problem is in the function parseXML.

Expand|Select|Wrap|Line Numbers
  1. var parseXML = function()
  2. {
  3.     var x=xml.documentElement.getElementsByTagName('name')  [0].nodeValue;
  4.     alert(x);
  5.  
  6. }
  7.  
I ran your code, but recoded your parseXML function, and it returned the name "rose" - as it should.

Expand|Select|Wrap|Line Numbers
  1. var parseXML = function()
  2. {
  3.     var x = xml.getElementsByTagName('name')[0].text;
  4.     alert(x);
  5. }
  6.  
Aug 31 '07 #3

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

Similar topics

3
by: iStrain | last post by:
Hiya. I'm _sure_ this is an FAQ, but Googling hasn't produced the answer in a way I can make sense out of. I know I should get this, but so far no way... I'm creating tables and doing queries in...
2
by: Deryck | last post by:
Hi, I am trying to update part of a webpage using javascript. The bit that gets updated will have a variable number of links written to it. I have done this successfully by rewriting the whole...
1
by: Stone Chen | last post by:
Hello, When I try to insert this line of code into my script, Firefox refuses to render. Could someone explain to me why that is? if (x.firstChild.firstChild.nodeValue==productID) { some code...
14
by: madtom1999 | last post by:
I'm trying to put a non-breaking space ( or any other entity for that matter) into a node eg: node.nodeValue+='&nbsp'; however the actual code is written in the html -ie it displays as >&nbsp;<...
1
by: Michael Landberg | last post by:
Hi I am looking for the other properties of nodeValue. I know only firstChild.nodeValue and lastChild.nodeValue. What other properties are there? Is there a property whit which I can get a...
1
by: yawnmoth | last post by:
What's the difference between the DOMNode proprties of nodeValue and textContent?
7
by: yawnmoth | last post by:
http://www.frostjedi.com/terra/scripts/demo/xml.html The first alert() shows the XML that the server is returning. The second alert() shows a particular elements nodeValue and, as you can see,...
7
by: Adam David Moss | last post by:
All, Long time since I've done some proper coding in ASP and I've hit a wee snag that has got me baffled. Well two actually but the other is to do with running pages under Sun ASP so we'll not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...

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.