各位:
对VB6编程不是很熟,在网上找过很多地方,都没找到如何像.NET那样设置版本号与字符集的方法。 xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", String.Empty)
请大家帮个忙,最好给一整段代码的例子。
多谢。
对VB6编程不是很熟,在网上找过很多地方,都没找到如何像.NET那样设置版本号与字符集的方法。 xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", String.Empty)
请大家帮个忙,最好给一整段代码的例子。
多谢。
Dim xmlNode As IXMLDOMNode
Set xmlDoc = New DOMDocument
Set xmlNode = xmlDoc.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'")
Set xXMLpi = Doc.createProcessingInstruction("xml", "version='1.0' encoding='utf-8'")
Dim strPath As String
Dim lngRecordLine As Long
Dim xmlDoc As DOMDocument
Dim xmlRoot As IXMLDOMElement
Dim xmlEle As IXMLDOMElement
Dim xmlNode As IXMLDOMNode
Dim xmlChildNode As IXMLDOMNode
Dim nFieldCount As Long
Dim rs As ADODB.Recordset
Dim i As Integer
Dim strRecord As String
lngRecordLine = 0
On Error GoTo ms
Set xmlDoc = New DOMDocument
Set xmlNode = xmlDoc.createProcessingInstruction("xml", "version='1.0' encoding='gb2312'")
Set xmlNode = xmlDoc.insertBefore(xmlNode, xmlNode.childNodes.Item(0))
Set xmlRoot = xmlDoc.createElement("RecordData")
Set xmlDoc.documentElement = xmlRoot
lngRecordLine = 1
Set rs = New ADODB.Recordset
Set rs = ExecuteSQL(strSql)
nFieldCount = rs.Fields.Count
Do Until rs.EOF
Set xmlEle = xmlDoc.createElement("Record" & lngRecordLine)
xmlRoot.appendChild xmlEle
strRecord = ""
For i = 1 To nFieldCount
xmlEle.setAttribute rs.Fields(i - 1).Name, rs.Fields(i - 1).value
Next i
lngRecordLine = lngRecordLine + 1
rs.MoveNext
Loop
rs.Close
CreateXMLString = xmlDoc.xml
lngLenght = Len(CreateXMLString)
Set xmlChildNode = Nothing
Set xmlNode = Nothing
Set xmlEle = Nothing
Set xmlRoot = Nothing
Set xmlDoc = Nothing
Exit Function
ms:
End Function