以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML源码及示例(仅原创和转载) 』  (http://bbs.xml.org.cn/list.asp?boardid=32)
----  求助,vb.net写xml的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=32&rootid=&id=21353)


--  作者:DirectX_Begin
--  发布时间:8/22/2005 3:42:00 PM

--  求助,vb.net写xml的问题
大家好,
我使用以下代码,为什么每次调用recordLog函数来写xml文件,每次都不能在xml文件里追加数据,(每次执行该代码系统都会重新写一个xml文件,的意思是在原文件中追加新数据。实现保存系统运行时出现的异常信息。)

请高人指教,谢谢

Public Sub recordLog(ByVal userID As String, ByVal modelName As String, Optional ByVal logType As String = "err", Optional ByVal logDescription As String = "")

        Try
            Dim myWrite As New Xml.XmlTextWriter(Application.StartupPath & "\eventlog.xml", Nothing)
            WriteLog(myWrite, userID, modelName, logType, logDescription)

            myWrite.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub WriteLog(ByVal writer As Xml.XmlTextWriter, ByVal userID As String, ByVal modelName As String, ByVal logType As String, ByVal logDescription As String)
        Try
            With writer
                .WriteStartDocument()
                .WriteWhitespace(" ")
                .Formatting = Xml.Formatting.Indented
                .WriteStartElement("eventlog")
                .WriteStartElement("eventcon")
                .WriteElementString("事件时间", System.DateTime.Now)
                .WriteElementString("操作人", userID)
                .WriteElementString("模块名称", modelName)
                .WriteElementString("事件类型", logType)
                .WriteElementString("事件描述", logDescription)
                .WriteEndElement()
                .WriteEndElement()
                .WriteEndDocument()
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
46.875ms