我有一个子程序,我试图用它来输出一些 XML,但是无论我做什么,输出文件都会将所有内容都写在同一行:这是我的代码,你能告诉我我可能出错的地方吗?
Private Sub CreateActionFile()
Dim lobjDirectory As New DirectoryInfo(mstrFolderName)
Dim lobjFiles As New List(Of FileInfo)
lobjFiles.AddRange(lobjDirectory.GetFiles("*.xml"))
Dim lobjWriter As XmlWriter = XmlWriter.Create(mstrFolderName & "\" & txtActionName.Text & ".xml")
Dim lobjSettings As New XmlWriterSettings()
lobjSettings.Indent = True
lobjSettings.NewLineOnAttributes = True
Dim lstrStartFileNumber As Integer = CInt(txtFrom.Text)
Dim lstrEndFileNumber As Integer = CInt(txtTo.Text)
lobjWriter.WriteStartElement("Action")
lobjWriter.WriteAttributeString("ID", Me.txtID.Text)
lobjWriter.WriteAttributeString("Name", Me.txtActionName.Text)
lobjWriter.WriteAttributeString("Type", "XML")
lobjWriter.WriteStartElement("xml")
While lstrEndFileNumber > lstrStartFileNumber
For Each lobjFile As FileInfo In lobjFiles
If lobjFile.Name.StartsWith(lstrStartFileNumber.ToString) Then
Dim lobjXmlDom As New XmlDocument
lobjXmlDom.Load(lobjFile.FullName)
lobjXmlDom.WriteContentTo(lobjWriter)
lstrStartFileNumber = lstrStartFileNumber + 1
Else
'Nothing - move on
End If
Next
End While
lobjWriter.WriteEndElement()
lobjWriter.WriteEndElement()
lobjWriter.WriteEndDocument()
lobjWriter.Close()
End Sub