如何从流中解析大型XML文件?

时间:2017-08-10 14:10:40

标签: .net xml vb.net

我有以下代码:

// load a über big xml file from a stream
Dim xmldoc As New XmlDocument
xmldoc.Load(logStream)

// squeeze it into the StringBuilder instance
Dim sb As New StringBuilder()
Using tw As New StringWriter(sb)
  Using xtw As New Xml.XmlTextWriter(tw)
    xtw.Formatting = Xml.Formatting.Indented
    xmldoc.WriteTo(xtw)
  End Using
End Using

// then write it to the file
Using fs = New FileStream(m_filename, If(logged, FileMode.Append, FileMode.Create), FileAccess.Write)
  Using sw As New StreamWriter(fs)
    sw.Write(sb.ToString())
  End Using
End Using

问题是logStream太大了,运行这段代码会炸毁整个建筑物。

我需要找到一种方法来逐行或以块或其他方式解析它。任何事情都没有。我想使用XmlDocument,因为它允许我应用缩进。

怎么做?

0 个答案:

没有答案