2015-02-12 59 views
0

我需要解析大(> 3GB)的XML文件,並通過我,像這樣的元素使用XmlTextReader的循環:VB.NET的XmlTextReader讀取字節

oReader = New XmlTextReader(filename) 
oReader.WhitespaceHandling = WhitespaceHandling.Significant 

While oReader.Read() 
    ' Processing in here 
End While 

由於這種預期需要很長的時間,我想提供一個進度指示器,表明迄今爲止已處理了多少XML文件。我的計劃是在處理之前獲取XML文件的總文件大小,然後保留XmlTextReader處理的字節數,以便計算完成百分比。但是,我無法弄清楚如何獲取XmlTextReader基礎數據流緩衝的字節數。有沒有辦法做到這一點?

回答

0

使用文件流作爲XMLTextReader的輸入,以便您可以從該流獲取當前位置。

Using _xmlfile As New IO.FileStream("x:\DocumentFormat.OpenXml.xml", IO.FileMode.Open) 
    Using oReader As New XmlTextReader(_xmlfile) 
     oReader.WhitespaceHandling = WhitespaceHandling.Significant 
      While oReader.Read() 
       ' Current filepos via: _xmlfile.Position 
       ' Processing in here 
      End While 
    End Using 
End Using