Mark Wilson I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :
03/24/2008
Times viewed :
2518
save()
Is a member of:
XML DOM Document
Syntax
objDOMDocument.save(objTarget)
Remark
The parameter objTarget can be a file name, an ASP response
object, an XML document object, or a custom object that supports
persistence and specific interfaces.
If you have manipulated the DOMDocument in any way by
appending, removing, or whatever, remember that it is not saved
to the XML file until you have called the save() method.
The save() method does not return anything; however, if an
error is reported, the error can expose one of the return values
listed in table .
0.0.1 save() method return values (continued)
Returned
Description
S_OK
Success
XML_BAD_ENCODING
The document contains a character
that does not belong in the specified encoding
E_INVALIDARG
A string was provided but it is not
a valid file name. or an object was provided that does not
support any of the above interfaces
E_ACCESSDENIED
save() operation is not
permitted
E_OUTOFMEMORY
save() cannot allocate buffers
Other values
Any other file system error
Saving in ADO
2.5
You may have noticed in previous examples that we tend to save
our XML to a file and then load the file into a DOMDocument. In
Microsoft ADO 2.5
that ships with Windows 2000, you will be able to save directly
to a DOMDocument.
This is how you will be able to do it:
Dim strSQL As String
Dim adoCon As ADODB.Connection
Dim adoRst As ADODB.Recordset
Dim objDOMDocument As DOMDocument
strSQL = "SELECT * FROM categories"
Set adoCon = New ADODB.Connection
Set adoRst = New ADODB.Recordset
adoCon.ConnectionString = "northwind"
adoCon.CursorLocation = adUseClient
adoCon.Open
Set adoRst.ActiveConnection = adoCon
adoRst.Open strSQL, , adOpenForwardOnly, _
adLockReadOnly, adCmdText
Set objDOMDocument = New DOMDocument
objDOMDocument.async = False
adoRst.Save objDOMDocument, 1 ' save this to DOM
adoRst.Close
adoCon.Close
Set adoCon = Nothing
¬ Prepare ADO objects.
¬ Open database connection.
¬ Get resultset.
¬ Prepare the DOMDocument.
¬ Save the recordset to the DOMDocument.
This manuscript is an abridged version of a chapter from the
Manning
Publications book XMLProgramming with VB and ASP. This chapter
looks at the Microsoft DOM objects. NOTE: Most images have been
removed to increase speed and many of the code comments have also
been removed for presentation. Please purchase the book to enjoy
the full experience of all the chapters with images and code
comments!