我正在使用 Visual Studio 2010 创建一个创建 .xml 文件的项目。但是,我在创建 .xml 格式的文件时遇到了问题,它目前只是作为没有 .xml 的文件格式输出。
Imports System
Imports System.Xml
Public Class Form1
Private Sub saveXML_Click(sender As System.Object, e As System.EventArgs) Handles saveXML.Click
Dim settings As New XmlWriterSettings()
settings.Indent = True
' Initialize the XmlWriter.
Dim XmlWrt As XmlWriter = XmlWriter.Create(txtConsumerID.Text.ToString(), settings)
With XmlWrt
' Write the Xml declaration.
.WriteStartDocument()
' Write the root element.
.WriteStartElement("PIAlertMonitor")
.WriteStartElement("ConsumerID")
.WriteString(txtConsumerID.Text.ToString())
.WriteEndElement()
.WriteStartElement("MaxAlerts")
.WriteString(MaxAlerts.Text.ToString())
.WriteEndElement()
.WriteStartElement("Notification")
.WriteStartElement("MailTo")
.WriteStartElement("eMail")
.WriteString(txteMail.Text.ToString())
.WriteEndElement()
' The end of this person.
.WriteEndElement()
' Close the XmlTextWriter.
.WriteEndDocument()
.Close()
End With
MessageBox.Show("XML File Saved")
End Sub
End Class