我才学大家不要笑话.请帮帮我
要生成这样的xml
<?xml version="1.0" encoding="GB2312"?>
- <DATA>
- <OBJECT NAME="表名" DESCRIPTION="组" COUNT="1">
- <RECORD>
  <F NAME="字段1">字段中数据1</F> 
  <F NAME="字段2">字段中数据2</F> 
  <F NAME="字段3">字段中数据3</F>  
  <F NAME="字段3" /> 
- <DATA>
- <OBJECT NAME="表名2" DESCRIPTION="组明细" COUNT="1">
- <RECORD>
  <F NAME="字段1">字段中数据1</F> 
  <F NAME="字段2">字段中数据2</F> 
  <F NAME="字段3">字段中数据3</F>  
  <F NAME="字段3" /> 
  </RECORD>
  </OBJECT>
  </RECORD>
  </OBJECT>
  </DATA>
2个表,其中count=1代表记录个数.字段3以/结尾代表该段中没数据.用vb连sqlserver
谢谢了.急呀??????????????????????????

解决方案 »

  1.   

    在工程中引用Microsoft XML v3.0Private Sub Command1_Click()
    a = readxml(App.Path & "\aa.xml", "itemName")
    MsgBox a
    b = writexml(App.Path & "\aa.xml", "itemName", "haha")
    MsgBox b
    End SubFunction readxml(fileName, itemName) As StringSet xmldoc = CreateObject("Msxml2.DOMDocument")
    xmldoc.async = False
    xmldoc.validateOnParse = False
    If xmldoc.Load(fileName) = False Then
        Set parseError = xmldoc.parseError
        MsgBox "Load xml failure." & vbCrLf & parseError.reason
        Exit Function
    End If
    Set iName = xmldoc.documentElement.selectSingleNode(itemName)readxml = iName.Text
    Set xmldoc = Nothing
    Set iName = NothingEnd FunctionFunction writexml(fileName, itemName, itemValue) As Boolean
    Set xmldoc = CreateObject("Msxml2.DOMDocument.4.0")
    Set objfso = CreateObject("Scripting.FileSystemObject")
    If Not objfso.fileexists(fileName) Then
        Dim pi As IXMLDOMProcessingInstruction
        Set pi = xmldoc.createProcessingInstruction("xml", "version=""1.0"" encoding=""GB2312""")
        xmldoc.insertBefore pi, xmldoc.childNodes.Item(0)
        Dim page As IXMLDOMElement
        Set page = xmldoc.createElement("root")
        Set xmldoc.documentElement = page
        xmldoc.save fileName
        writexml = False
        Exit Function
    End Ifxmldoc.async = False
    xmldoc.validateOnParse = False
    xmldoc.Load (fileName)
    Set iName = xmldoc.documentElement.selectSingleNode(itemName)
    iName.Text = itemValue
    xmldoc.save fileNamewritexml = True
    Set xmldoc = Nothing
    Set objfso = Nothing
    End Function