共用方式為


loadXML Method1

 

Loads an XML document using the supplied string.

JScript 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.3.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;
   WScript.Echo("You have error " + myErr.reason);
} else {
   WScript.Echo(xmlDoc.xml);
}

Output

<customer><first_name>Joe</first_name><last_name>Smith</last_name></customer>

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.

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

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 MSXML 6.0

See Also

documentElement Property
load Method1
Persistence and the DOM
IXMLDOMDocument-DOMDocument