0

I have a XML String with in the <xml> tags in a .jsp file and I am trying to load that xml using xmldoc.Load(document.all("Info")) and it is giving an error

Invalid procedure call or argument

but everything works in Ie9. When I inspect the document.all("Info") it says

Object UnknownHTMLElement in IE 10 and Object in IE9.

here is the code snippet which I used

var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
boolXMLLoaded=xmldoc.load (document.all("UserInfo"))
    <xml id=UserInfo>`
<?xml version='1.0'?><RESPONSES UserName="  DOUGLAS  ................
</xml>

Any help is greatly appreciated..

Christian-G
  • 2,371
  • 4
  • 27
  • 47
Harish
  • 425
  • 3
  • 7
  • 19

2 Answers2

0

The reason your code doesn't work in newer IE versions is because you're using obsolete (very very obsolete) code. You need to update to modern web standards if you expect modern browsers (including IE10) to work.

Two issues are obvious immediately:

  1. document.all has been deprecated for years; you shouldn't be using it -- it is non-standard and only still exists to allow backward-compatibility with ancient versions of IE (eg IE5). Modern IE versions won't like it, and it definitely doesn't work on browsers other an IE.

    In most cases, if you're trying to reference an element by ID (as in this case), you should use document.getElementById() instead.

    Further info from Mozilla Developer Network.

  2. new ActiveXObject("MSXML2.DOMDocument.3.0") is also non-standard and deprecated, and also shouldn't be used in modern browsers. Again, it is IE-specific, and was replaced from IE7 onward with the web standards alternative.

    You should replace it with document.implementation.createHTMLDocument();. See also the anwsers here.

    If you need to support IE6 or earlier then you can detect whether the browser supports the standard syntax and provide a fall back to the old ActiveX control only for old IE versions.

Given that the tiny bit of code you've shown us is using two obvious and well known features that are so badly out-of-date, I would expect to see more problems of a similar nature if we were to see more of your code. Because of this, I would recommend posting some of your code on SO's sister site https://codereview.stackexchange.com/ to get some additional feedback on how you can improve it.

Hope that helps.

Community
  • 1
  • 1
Spudley
  • 166,037
  • 39
  • 233
  • 307
  • Thanks a lot for you reply.. I have modified the code in the following way var xmldoc= document.getElementById("UserInfo"); RegionNode=xmldoc.selectNodes("//RESPONSES//Region"); strUserName =xmldoc.lastChild.getAttribute("UserName"); Everything works in Ie9 but not in IE10 and getting error in Ie10 Object doesn't support property or method 'selectNodes' can you provide a code snippet to load the xml into a document in IE10? or how can we access the xml in the java script in IE10. how can we traverse through xml – Harish Apr 22 '13 at 17:30
0
var xmldoc= new ActiveXObject("Microsoft.XMLDOM");

replace this in place of

var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");

and try it again

bofredo
  • 2,348
  • 6
  • 32
  • 51