Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

Saves an XML document to the specified location.

Script Syntax

Copy Code
oXMLDOMDocument.save(
destination);

Remarks

Script Parameters

destination

Object. The object can represent a file name, an ASP Responseobject, a DOMDocumentobject, or a custom object that supports persistence. See General Remarks.

Script Return Value

None.

C/C++ Syntax

Copy Code
HRESULT save(
  VARIANT 
destination
);

Remarks

C/C++ Parameters

destination

[in] Type of object to save. This object can represent a file name, an ASP Responseobject, an XML document object, or a custom object that supports persistence. See Remarks.

C/C++ Return Values

S_OK

Value returned if successful.

XML_BAD_ENCODING

The document contains a character that does not belong in the specified encoding. The character must use a numeric entity reference. For example, the Japanese Unicode character 20013 does not fit into the encoding windows-1250 (the Central European alphabet) and therefore must be represented in markup as the numeric entity reference 中 or 中. This version of savedoes not automatically convert characters to the numeric entity references.

E_INVALIDARG

A string was provided, but it is not a valid file name.

E_ACCESSDENIED

Save operation is not permitted.

E_OUTOFMEMORY

Save must allocate buffers.

(Other values)

Any other file system error can be returned in the save( string) case.

Requirements

Header msxml2.h, msxml2.idl
Library uuid.lib
Windows Embedded CE Windows CE .NET 4.0 and later

General Remarks

The behavior differs based on the object specified by the objTargetparameter.

Object Description

String

Specifies the file name. Note that this must be a file name rather than a URL. The file is created if necessary and the contents are entirely replaced with the contents of the saved document. This mode is not intended for use from a secure client such as Microsoft® Internet Explorer.

Copy Code
	dim xmldoc
	set xmldoc = Server.CreateObject("Msxml2.DOMDocument")
	xmldoc.load("c:\myfile.xml")
	xmldoc.save(Server.MapPath("sample.xml"))

The Active Server Pages (ASP) Responseobject sends the document back to the client that invoked the ASP script.

Copy Code
	dim xmldoc
	set xmldoc = Server.CreateObject("Msxml2.DOMDocument")
	xmldoc.load(Server.MapPath("sample.xml"))
	xmldoc.save(Response)

IXMLDocumentObject

Duplicates the original document. It is the equivalent of saving the document and reparsing it. The document goes through full persistence through XML markup, thereby testing the persistability of your XML document.

Copy Code
	<script language="jscript">
		var xmldoc1 = new ActiveXObject("Msxml2.DOMDocument");
		var xmldoc2 = new ActiveXObject("Msxml2.DOMDocument");
		xmldoc1.load("sample.xml");
		xmldoc1.save(xmldoc2.XMLDocument);
	</script>

Custom object supporting persistence

Any other custom COM object that supports QueryInterfacefor IStream, IPersistStream, or IPersistStreamInitcan also be provided here, and the document will be saved accordingly. In the IStreamcase, the IStream Writemethod will be called as it saves the document; in the IPersistStreamcase, IPersistStream Loadwill be called with an IStreamthat supports the Read, Seek, and Statmethods.

External entity references in DOCTYPE, ENTITY, NOTATION, and XML namespace declarations are not changed; they point to the original document. A saved XML document might not load if the URLs are not accessible from the location in which you saved the document.

Character encoding is based on the encoding attribute in the XML declaration, such as <?xml version="1.0" encoding="windows-1252"?>. When no encoding attribute is specified, the default setting is UTF-8.

Validation is not performed during save, which can result in an invalid document that does not load again because of a specified document type definition (DTD). This member is an extension of the World Wide Web Consortium (W3C) Document Object Model (DOM).

This method applies to the following interface:

DOMDocument.