簡體   English   中英

什么是XML空屬性,以及如何在Linq-To-XML中處理它們?

[英]What is a XML null attribute, and how to handle them in Linq-To-XML?

我正在嘗試將XmlReader讀入XDocument

//GetContentStructureReader() retrieves the reader from an external source
XmlReader reader = GetContentStructureReader();
XDocument.Load(reader);

對於一個特定的數據源,我不斷收到以下異常:

用戶代碼未處理System.ArgumentNullException Message = Value不能為null。 參數名稱:值Source = System.Xml.Linq ParamName =值StackTrace:位於System.Xml.Linq.XAttribute..ctor(位於System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)處System.Xml.Linq.XDocument.Load(XmlReader閱讀器,LoadOptions選項)上的.Xml.Linq.XContainer.ReadContentFrom(XmlReader r,LoadOptions o)在System.Xml.Linq.XDocument.Load(XmlReader閱讀器)

因此,似乎在加載期間,某個XAttribute正在使用null值初始化。

XML中的null屬性是什么? 我嘗試檢查(6兆字節)源文檔以更正數據,但由於我不知道要尋找哪種XML構造而徒勞無功。

有沒有解決方法?

在加載文檔期間,空值不應顯示為XAttribute的值。 因此,您所看到的是意外的。 您可以在調試器中停止該異常,以查看調用堆棧和參數值(特別是XName名稱),這可能有助於您在源文檔中定位屬性。 (您也可以在what窗口中的確實定義了閱讀器的其中一個框架上嘗試[[(IXmlLineInfo)reader)。在任何情況下,.NET Framework中XmlReader的默認實現都不會導致這種情況。所以問題是,您在哪里/如何創建了傳遞給Load方法的XmlReader對象的實例?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM