扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:crystal编译 来源:天极网 2007年10月14日
关键字:
<Values> <FirstName>Rod</FirstName> <LastName>Stephens</LastName> <Street>1234 Programmer Place</Street> <City>Bugsville</City> <State>CO</State> <Zip>80276</Zip> </Values> |
Option Explicit Private m_AppPath As String 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") ' Read the saved values. txtFirstName.Text = GetNodeValue(values_node, "FirstName", "???") txtLastName.Text = GetNodeValue(values_node, "LastName", "???") txtStreet.Text = GetNodeValue(values_node, "Street", "???") txtCity.Text = GetNodeValue(values_node, "City", "???") txtState.Text = GetNodeValue(values_node, "State", "???") txtZip.Text = GetNodeValue(values_node, "Zip", "???") End Sub ' 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 ' Create nodes for the values inside the ' Values section node. CreateNode values_node, "FirstName", txtFirstName.Text CreateNode values_node, "LastName", txtLastName.Text CreateNode values_node, "Street", txtStreet.Text CreateNode values_node, "City", txtCity.Text CreateNode values_node, "State", txtState.Text CreateNode values_node, "Zip", txtZip.Text ' 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 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者