2011-04-04 51 views
-2

我正在讀作爲一個巨大的xml文檔(1.7克)的icecat表,我用的是xmlnodereader。我怎樣才能從xmlnodereader得到一個xmlnode

如何逐個節點讀取它。我知道,通常情況下,你不會這麼做,但結構看起來像

<file attr=value>...</file> 


<file attr=value>...</file> 


<file attr=value>...</file> 


<file attr=value>...</file> 


<file attr=value>...</file> 

這裏是參考一些現有的代碼:

foreach (BackgroundWorker worker in Pool) 
      { 
       if (worker.IsBusy) 
        continue; 
       //read xmlnode and pass it to the worker 

      } 

回答

1

我建議,如果你能使用LINQ to XML。你可以使用:

XElement element = XElement.Load(reader); 

它將只從讀取器加載一個單一的元素,推進它適當。這很容易做到,而LINQ to XML API比舊的DOM API好得多。