• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

responseXML.documentElement is null

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am trying to get the contents of XML( from myXml.xml in my local system) and display the same in HTML in the onLoad event. But i am getting a JS error - ""Unable to get property 'getAttribute' of undefined or null reference "" in line number 38 of stateChanged method.

Can you please let me know how to resolve this. Please find the programs below


Thanks in advance.


Main Program:



myXml.xml
-------------


 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted or unindented code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please click this link ⇒ UseCodeTags ⇐ for more information. Properly indented and formatted code greatly increases the probability that your question will get quicker, better answers.

I've gone ahead and added the code tags for you. See how much easier the code is to read?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's usually a sign that the content type header in the response is not correctly set.
 
pradeep chellappan rm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

I have given the content-type as below

<meta http-equiv="content-type" content="text/xml; charset=UTF-8">

But this is not working. I am not sure what different header type is expected to fix the issue. Please advise.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The content type of the page is moot. What's the content type of the XML response?
 
pradeep chellappan rm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

Thanks for your response. I am sorry to say that i am lacking understanding on content Type. I googled to find out, and majority of the cases it is in servlet, the content type is set. But this program is not actually hitting any server, but considers the local machine as server. So, the content type of response xml has to be set in javascript, which i am not sure how to do it. If you can assist me with this, it will be really helpful.

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Even if you are hitting the local server, the XML is being served by HTTP. You should be able to use the debugging tools in any modern browser to look at the network HTTP info and see what the content type is being set to.
 
pradeep chellappan rm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bear,

I tried with IE9, developer toolbar. In the network tab, i am not seeing any information on Request body, Response headers, Response body. I think your suggestion was to look into these. Please let me know what i am missing?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't have Windows handy so I can't check in IE9. Try the Chrome tools, or Firefox with Firebug installed. Be sure tracking Ajax calls are enabled.

(These are tools you need to know how to use if you are going to be working with web apps.)
 
author
Posts: 297
5
Android Firefox Browser Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What URL are you accessing your page on, is it a file:// or http:// address? If it's file:// you may not be able to use Ajax due to browser security restrictions, certainly you wouldn't get any network headers (because there's no network request).
 
pradeep chellappan rm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rob,

I am indeed using file protocol to access the xml file from HTML. This program though is working in Firefox but not in IE & Chrome. In Chrome debugger, the issue was more explicit- Cross origin requests are only supported for HTTP."Do you know why it would run on Firefox & can you please elobrate few points on security, please?

Bear - Thanks a lot for your suggestions.

Fyi, I happen to try running the program in eclipse and it was working fine.


 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The file protocol is not HTTP and so HTTP headers are moot. if you want all this to work, you'll need to use HTTP.
 
pradeep chellappan rm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bear,

I was not understanding the meaning of the word "moot". Your clarification on that now makes sense. Thanks a lot.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In other words, irrelevant.
 
reply
    Bookmark Topic Watch Topic
  • New Topic