Click to Rate and Give Feedback
MSDN
MSDN Library
MSXML
DOM
DOM Reference
XML DOM Methods
 load Method

  Switch on low bandwidth view
load Method

Loads an XML document from the specified location.

JScript Syntax

boolValue = oXMLDOMDocument.load(xmlSource);

Parameters

xmlSource

A string containing a URL that specifies the location of the XML file.

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.

NoteNote

You can use books.xml to run this sample code.

J#
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.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.

Visual Basic Syntax

boolValue = oXMLDOMDocument.load(xmlSource)

Parameters

xmlSource

A string containing a URL that specifies the location of the XML file.

Return Value

Boolean. Returns True if the load succeeded; False if the load failed.

Example

The following Microsoft Visual Basic® example creates a DOMDocument object and uses the load method to load a local XML file.

NoteNote

You can use books.xml to run this sample code.

Visual Basic
Dim xmlDoc As New Msxml2.DOMDocument30
xmlDoc.async = False
xmlDoc.Load App.Path & "\books.xml"
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   MsgBox xmlDoc.xml
End If

Output

Outputs the books.xml file.

C/C++ Syntax

HRESULT load(
    VARIANT xmlSource,
    VARIANT_BOOL *isSuccessful);

Parameters

xmlSource[in]

An indicator of the source XML to parse. This may be an URL (String/BSTR), a Request object (in an ASP page), an IStream, SAFEARRAY of bytes (VT_ARRAY|VT_UI1), a DOMDocument object, or any object that supports IStream, ISequentialStream, or IPersistStream. See Remarks for more information.

isSuccessful[out, retval]

True if the load succeeded; False if the load failed.

Return Values

S_OK

The value returned if successful.

S_FALSE

The value returned if the load fails.

E_INVALIDARG

The value returned if the isSuccessful parameter is Null.

Remarks

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:

Visual Basic Script
Set objXML = CreateObject("Msxml2.DOMDocument.3.0")
ObjXML.async=true
objXML.load "res://msxml3.dll/DEFAULTSS.XSL"
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   WScript.Echo("You have error " + myErr.reason);
} else {
   WScript.echo objXML.parseError.reason
   objXML.save "defaultss.xsl"
}

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.

Versioning

Implemented in: MSXML 3.0 and later

See Also

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker