0

In Microsoft Internet Explorer we can use Msxml2.DOMDocument.6.0 activeX component

to do xslt based transformation using the transformNode() method. We can load an xml

or xslt by the following method :

var activeX = new ActiveXObject("Msxml2.DOMDocument.6.0");
activeX.load('webdirectories/xml/somefile.xml');

but can we load an xml by providing the xml as a string variable instead of providing the

location of the xml file? something like this-

var xmlFileContents = '<?xml version="1.0"?><books> .... </books>';
Ranjan Sarma
  • 1,565
  • 5
  • 22
  • 36

1 Answers1

0

Yes, there is a method loadXML you can use e.g.

if (activeX.loadXML(xmlfileContents)) {
  // now you can access DOM here
}
else {
  // check activeX.parseError.reason and errorCode here
}
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • kindly check the correctness of the below code sir: var xmlString = ' – Ranjan Sarma Apr 05 '12 at 10:44
  • Microsoft only supports XML 1.0 so make sure if your XML has an XML declaration with the version number that is says `` and not `1.1` as in your sample. And I intentionally showed how to check whether the XML was parsed successfully so follow that line of code so that you can see any parsing error the parser might report to you. And `activeX.transformNode('')` is not going to work, you need to pass a DOM node with the stylesheet code. Also see the MSXML documentation http://msdn.microsoft.com/en-us/library/windows/desktop/ms763742%28v=vs.85%29.aspx. – Martin Honnen Apr 05 '12 at 16:45