Saves an XML document to the specified location.
oXMLDOMDocument.save(destination)
HRESULT save( VARIANT varObject);
The behavior of the save method differs based on the object specified by the varObject parameter.
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 Internet Explorer because the method always returns E_ACCESSDENIED and cannot be enabled through user security settings. For example:
dim xmldoc set xmldoc = Server.CreateObject("Msxml2.DOMDocument") xmldoc.load(Request) xmldoc.save(Server.MapPath("sample.xml")) |
ASP Response object | Sends the document back to the client that invoked the ASP script. For example:
dim xmldoc set xmldoc = Server.CreateObject("Msxml2.DOMDocument") xmldoc.load(Server.MapPath("sample.xml")) xmldoc.save(Response) |
XML document object | 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. For example:
<script language="jscript"> var xmldoc1 = CreateObject("Msxml2.DOMDocument"); var xmldoc2 = CreateObject("Msxml2.DOMDocument"); xmldoc1.load("sample.xml"); xmldoc1.save(xmldoc2.XMLDocument); </script> |
Custom object supporting persistence | Any other custom COM object that supports QueryInterface for IStream, IPersistStream, or IPersistStreamInit can also be provided here, and the document will be saved accordingly. In the IStream case, the IStream::Write method will be called as it saves the document; in the IPersistStream case, IPersistStream::Load will be called with an IStream that supports the Read, Seek, and Stat methods. |
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 DTD.
When manipulating a document, it is possible to create a document that lacks the appropriate namespace declarations to be reparsed or to have declarations that would cause some prefixed names to be interpreted incorrectly. When saving an XML representation of DOM nodes, the Microsoft XML parser (MSXML) attempts to insert appropriate namespace declarations to preserve the original namespace URI for each element and its attributes.
BOOL DOMDocSaveLocation() { BOOL bResult = FALSE; IXMLDOMDocument *pIXMLDOMDocument = NULL; HRESULT hr; try { _variant_t varString = _T("D:\\sample.xml"); // Initialize pIXMLDOMDocument (create a DOMDocument). // Load document. hr = pIXMLDOMDocument->save(varString); if(SUCCEEDED(hr)) bResult = TRUE; } catch(...) { DisplayErrorToUser(); // Release the IXMLDOMDocument interface. } // Release the IXMLDOMDocument interface when finished with it. return bResult; }
IXMLDOMDocument Interface | XML DOM Persistence