' Save the XML document.
xml_document.save m_AppPath & "Values.xml"
End Sub
' Add a new node to the indicated parent node.
Private Sub CreateNode(ByVal indent As Integer, _
ByVal parent As IXMLDOMNode, ByVal node_name As String, _
ByVal node_value As String)
Dim new_node As IXMLDOMNode
' Add a new node to the indicated parent node.
Private Sub CreateNode(ByVal indent As Integer, _
ByVal parent As IXMLDOMNode, ByVal node_name As String, _
ByVal node_value As String)
Dim new_node As IXMLDOMNode
' Create the new node.
Set new_node = parent.ownerDocument.createElement(node_name)
' Set the node's text value.
new_node.Text = node_value
' Add the node to the parent.
parent.appendChild new_node
End Sub
SaveValues 程序
Private Sub Form_Load()
' Get the application's startup path.
m_AppPath = App.Path
If Right$(m_AppPath, 1) <> "\" Then m_AppPath = m_AppPath & "\"
' Load the values.
LoadValues
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Save the current values.
SaveValues
End Sub
' Load saved values from XML.
Private Sub LoadValues()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode
' Load the document.
Set xml_document = New DOMDocument
xml_document.Load m_AppPath & "Values.xml"
' If the file doesn't exist, then
' xml_document.documentElement is Nothing.
If xml_document.documentElement Is Nothing Then
' The file doesn't exist. Do nothing.
Exit Sub
End If
' Find the Values section.
Set values_node = xml_document.selectSingleNode("Values")
' Return the node's value.
Private Function GetNodeValue(ByVal start_at_node As IXMLDOMNode, _
ByVal node_name As String, _
Optional ByVal default_value As String = "") As String
Dim value_node As IXMLDOMNode
Set value_node = start_at_node.selectSingleNode(".//" & node_name)
If value_node Is Nothing Then
GetNodeValue = default_value
Else
GetNodeValue = value_node.Text
End If
End Function
' Save the current values.
Private Sub SaveValues()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode
' Create the XML document.
Set xml_document = New DOMDocument
' Create the Values section node.
Set values_node = xml_document.createElement("Values")
' Add the Values section node to the document.
xml_document.appendChild values_node
' Save the XML document.
xml_document.save m_AppPath & "Values.xml"
End Sub
' Add a new node to the indicated parent node.
Private Sub CreateNode(ByVal parent As IXMLDOMNode, _
ByVal node_name As String, ByVal node_value As String)
Dim new_node As IXMLDOMNode
' Create the new node.
Set new_node = parent.ownerDocument.createElement(node_name)
' Set the node's text value.
new_node.Text = node_value
' Add the node to the parent.
parent.appendChild new_node
End Sub
出于安全的原因,对由 Microsoft Internet Explorer 执行的脚本,Save 方法仅允许使用低的和自定义的安全设置。有关安全问题的详细解释,请参阅 在 http://www.microsoft.com/data/techmat.htm 上的白皮书标题“Security Issues in the Microsoft Internet Explorer”。
如果正在进行异步 Recordset 获取、执行或更新操作时调用 Save 方法,则 Save 将进入等待状态,直到异步操作完成。
在 Save 方法完成后,当前行位置将成为 Recordset 的首行。
要得到最佳结果,应使用 Save 将 CursorLocation 属性设置为 adUseClient。如果您的提供者不支持用于保存 Recordset 对象的所需功能,则客户端游标将提供该功能。
Recordset 持久性
使用记录集持久性,可以将 Recordset 数据和元数据保存为文件。随后,使用持久文件来重新建立 Recordset 对象。持久文件可以保存在本地驱动器、网络服务器上或者作为 URL 保存在 Web 站点上。