views:

31

answers:

1

Hello again; i try to save xml data from xml file. How can i do that? if i use below codes, XmlStream return null "throw null". How can do that?

my data:


<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;
       }

Main Program:

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

You're loading the assembly resource incorrectly. Instead of just User.xml, you need yourNamespace.User.xml. If your resource is inside a folder within the project, that will be reflected in the final name as well.

Check out this example.

Will Eddins
i rearranged my ques. But result is the same...
Phsika
Are you compiling with the XML file set as an embedded resource?
Will Eddins