loadXML Method

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - DOM Reference

loadXML Method

Loads an XML document using the supplied string.

[Script]

Script Syntax

boolValue = oXMLDOMDocument.loadXML(bstrXML);

Parameters

bstrXML
A string containing the XML string to load into this XML document object. This string can contain an entire XML document or a well-formed fragment.

Return Value

Boolean. Returns True if the XML load succeeded. Returns False and sets the documentElement property of the DOMDocument to Null if the XML load failed.

Example

The following script example creates a DOMDocument object, and then uses its loadXML method to load the specified XML before displaying it.

var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.5.0");
xmlDoc.async = false;
xmlDoc.loadXML("<customer><first_name>Joe</first_name><last_name>Smith</last_name></customer>");
if (xmlDoc.parseError.errorCode <> 0) {
   var myErr = xmlDoc.parseError;
   alert("You have error " + myErr.reason);
} else {
   alert(xmlDoc.xml);
}
[Visual Basic]

Visual Basic Syntax

boolValue = oXMLDOMDocument.loadXML(bstrXML)

Parameters

bstrXML
A string containing the XML string to load into this XML document object. This string can contain an entire XML document or a well-formed fragment.

Return Value

Boolean. Returns True if the XML load succeeded. Returns False and sets the documentElement property of the DOMDocument to Null if the XML load failed.

Example

The following Microsoft® Visual Basic® example creates a DOMDocument object, and then uses its loadXML method to load the specified XML before displaying it.

Dim xmlDoc As New Msxml2.DOMDocument50
xmlDoc.async = False
xmlDoc.loadXML ("<customer>" & _
                "<first_name>Joe</first_name>" & _
                "<last_name>Smith</last_name></customer>")
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   MsgBox xmlDoc.xml
End If
[C/C++]

C/C++ Syntax

HRESULT loadXML(
    BSTR bstrXML,
    VARIANT_BOOL * isSuccessful);

Parameters

bstrXML [in]
An XML string to load into this XML document object. This string can contain an entire XML document or a well-formed fragment.
isSuccessful [out, retval]
True if the XML load succeeded. If the XML load failed, this method returns False and sets the documentElement property of the DOMDocument object to Null.

C/C++ 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

Calling load or loadXML on an existing document immediately discards the content of the document. The loadXML() method will work only with UTF-16 or UCS-2 encodings.

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).

To view reference information for Visual Basic, C/C++, or Script only, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

documentElement property | load Method | Persistence and the DOM

Applies to: DOMDocument