Question

I'm trying to create an object to work with XML later but no luck:

var objXML = new ActiveXObject( "Microsoft.XMLDOM" );
WScript.Echo("objXML:"+objXML.constructor); 

var objXML2 =  WScript.CreateObject("Msxml.DOMDocument");
WScript.Echo("objXML2:"+objXML2.constructor);

The output is

Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

objXML:undefined
objXML2:undefined

OS: Win2003 Ent SP2

What am I doing wrong? How can I manipulate an XML file assuming I CANNOT load any custom library on the server - just using Windows default libs?

Was it helpful?

Solution

The objects corresponding to the progids Msxml.DOMDocument and Microsoft.XMLDOM don't expose a member called constructor through IDispatch.

To verify that the object has been successfully returned, you could try using members that are part of the interface defined by IXMLDOMDocument instead.

For example, changing your script thus:

var objXML = new ActiveXObject( "Microsoft.XMLDOM" );
objXML.loadXML("<x/>")
WScript.Echo("objXML:"+objXML.xml); 

var objXML2 =  WScript.CreateObject("Msxml.DOMDocument");
WScript.Echo("objXML2:"+objXML2.nodeTypeString);

gives:

objXML:<x/> 
objXML2:document

Note that if the objects were not being created, you would receive an exception ("Could not locate automation class...") at the point at which you attempt the creation, which you would see if you had a typo in the progid, thus: new ActiveXObject( "MicrosoftX.MLDOM" );

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top