2009-07-03 18 views
1

再次您好!我嘗試保存xml文件中的xml數據。我怎樣才能做到這一點?如果我使用下面的代碼,XmlStream返回null「throw null」。怎麼可以做到這一點?xlinq扔空數據?我該如何解決它?

我的數據:


<list> 
    <subscriber Type="Random"> 
    <name>yusuf</name> 
    <surname>karatoprak</surname> 
    </subscriber> 
</list> 

public static XDocument GetRawsSnippetAsXDocuments() 
     { 
      Assembly assembly = Assembly.GetExecutingAssembly(); 
      Stream xmlStream = assembly.GetManifestResourceStream("XlinqTest1.User.xml"); 
      if (xmlStream == null) 
      { 
       throw new NullReferenceException("Hata!!!"); 
      } 
      XDocument xmlDocument = XDocument.Load(XmlReader.Create(xmlStream)); 

      return xmlDocument; 
     } 

主要課程:

class Program 
    { 
     static void Main(string[] args) 
     { 
      XDocument document = XmlHelper.GetRawsSnippetAsXDocuments(); 
      var listCount = document.Descendants("list").Count(); 
     } 
    }

回答

1

你沒有正確地加載程序集資源。而不僅僅是User.xml,您需要yourNamespace .User.xml。如果您的資源位於項目內的文件夾內,那麼也會反映在最終名稱中。

Check out this example.

+0

我重新安排了我的問題。但結果是一樣的... – Penguen 2009-07-03 18:36:09

相關問題