文档内容
 <?xml version="1.0" standalone="yes" ?> 
- <NewDataSet>
- <SELECT_x0020_TOP_x0020_10_x0020_DB_x002C_ACC_NAME_x0020_FROM_x0020_ACC>
  <SUN_DB>001</SUN_DB> 
  <ACCNT_NAME>现金-RMB</ACCNT_NAME> 
  </SELECT_x0020_TOP_x0020_10_x0020_DB_x002C_ACC_NAME_x0020_FROM_x0020_ACC>
- <SELECT_x0020_TOP_x0020_10_x0020_DB_x002C_ACC_NAME_x0020_FROM_x0020_ACC>
  <SUN_DB>001</SUN_DB> 
  <ACCNT_NAME>现金-USD</ACCNT_NAME> 
  </SELECT_x0020_TOP_x0020_10_x0020_DB_x002C_ACC_NAME_x0020_FROM_x0020_ACC>
  </NewDataSet>想将SELECT_x0020_TOP_x0020_10_x0020_DB_x002C_ACC_NAME_x0020_FROM_x0020_ACC修改为ABC程序代码为
 Dim XmlDoc As XmlDocument = New XmlDocument
        XmlDoc.Load("c:\abc.xml")
        Dim root As XmlNode = XmlDoc.DocumentElement
        Dim xn As XmlNode
        For Each xn In root.ChildNodes
            If xn.Name = "SELECT_x0020_TOP_x0020_10_x0020_DB_x002C_ACC_NAME_x0020_FROM_x0020_ACC" Then '
                xn.Name = "abc"
            End If
        Next
        XmlDoc.Save("c:\bookstore.xml")但xn.name="abc"提示错误,我不知道为什么请教,超急,谢谢

解决方案 »

  1.   

    Private m_AppPath As StringPrivate 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 SubPrivate 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 DOMDocumentxml_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 IXMLDOMNodeSet 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.createProcessingInstruction("xml", " version='1.0' encoding='GB2312'")xml_document.appendChild values_node' Add a new line.
    Set values_node = xml_document.createElement("Values")
    values_node.appendChild xml_document.createTextNode(vbCrLf)' Add the Values section node to the document.xml_document.appendChild values_node' Create nodes for the values inside the
    ' Values section node.
    CreateNode 4, values_node, "FirstName", txtFirstName.Text
    CreateNode 4, values_node, "LastName", txtLastName.Text
    CreateNode 4, values_node, "Street", txtStreet.Text
    CreateNode 4, values_node, "City", txtCity.Text
    CreateNode 4, values_node, "State", txtState.Text
    CreateNode 4, 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 indent As Integer, _
    ByVal parent As IXMLDOMNode, ByVal node_name As String, _
    ByVal node_value As String)
    Dim new_node As IXMLDOMNode' Indent.
    parent.appendChild _
    parent.ownerDocument.createTextNode(Space$(indent))' 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' Add a new line.
    parent.appendChild parent.ownerDocument.createTextNode(vbCrLf)
    End Sub