Click here to Skip to main content
15,919,028 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I encountered a problem, the following code can run properly in Microsoft IE browser, but can not run on Google Chrome browser.

XML document structure:
<?xml version="1.0"?>
     <bookname>C# Programming</bookname>
     <bookname>C++ Programming</bookname>
     <bookname>Java Programming</bookname>

javascript codes:
<script type="text/javascript">
      function getXMLValue() {

          if (window.XMLHttpRequest) {
              xmlhttp = new XMLHttpRequest();
          else {
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

"GET", "books.xml", false);
          xmlDoc = xmlhttp.responseXML;

          var bNumber = xmlDoc.getElementsByTagName("book");
          for (var i = 0; i < bNumber.length; i++) {
              for (var j = 0; j < 3; j++) {
                  // Visit belong to all child nodes  of 'book' .



Google Chrome prompt:Uncaught TypeError: Cannot read property 'nodeValue' of undefined
Updated 26-May-14 4:17am
Did you debug and see what is the exact issue?
Ken H123 26-May-14 10:02am    
Uncaught TypeError: Cannot read property 'nodeValue' of undefined

I cant see how it works in IE!
Your XML has a two level>author/price.
xmlDoc.getElementsByTagName("book")[i] gets the book level
and xmlDoc.getElementsByTagName("book")[i].childNodes[j] gets the author/price level.
So xmlDoc.getElementsByTagName("book")[i].childNodes[j].childNodes[0] should be undefined...
Remove .childNodes[0]!!!
Share this answer
Ken H123 26-May-14 10:34am    
My problem has been updated.
You are getting issues because of cross-browsers differences. Very nice discussion is given here.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900