load Method
Loads an XML document from the specified location.
boolValue = oXMLDOMDocument.load(xmlSource);
Parameters
Return Value
Boolean. Returns True if the load succeeded; False if the load failed.
Example
The following script example creates a DOMDocument object and uses the load method to load a local XML file.
Note |
|---|
You can use books.xml to run this sample code. |
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0"); xmlDoc.async = false; xmlDoc.load("books.xml"); if (xmlDoc.parseError.errorCode != 0) { var myErr = xmlDoc.parseError; WScript.Echo("You have error " + myErr.reason); } else { WScript.Echo(xmlDoc.xml); }
Output
Outputs the books.xml file.
If the URL cannot be resolved or accessed or does not reference an XML document, this method returns an error and sets the documentElement property of the DOMDocument to Null.
The load method can also take any object that supports IStream and the Microsoft® Internet Information Services (IIS) Request object.
Calling load or loadXML on an existing document immediately discards the content of the document.
If loading an XML document from a resource, the load must be performed asynchronously or the load will fail. For example:
Set objXML = CreateObject("Msxml2.DOMDocument.6.0")
ObjXML.async=true
objXML.load "res://msxml3.dll/xml/defaultss.xsl"
If objXML.parseError.errorCode <> 0 Then
Set myErr = objXML.parseError
WScript.Echo "You have error " + myErr.reason
Else
WScript.Echo objXML.parseError.reason
objXML.save "defaultss.xsl"
End If
You can use this method to check if the loaded XML document is well-formed. You cannot use it to validate the XML document against a schema.
This member is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).
When a document is loaded using this method, URLs will be resolved relative to the directory from which the program executed.
Note