title: C# - Array from XML as an embedded resource
body: <p>I've been trying to find a good clean way to load the contents of an XML file into an array to use but I've only found partial answers here and there. My XML file is an Embedded Resource for simplicity, and contains a list of about 115 elements that all contain an <code>id</code> and <code>name</code> attribute.</p>
  
  <p>The XML looks like so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;Items xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;Item&gt;
          &lt;id&gt;1&lt;/id&gt;
          &lt;name&gt;Example1&lt;/name&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;id&gt;2&lt;/id&gt;
          &lt;name&gt;Example2&lt;/name&gt;
      &lt;/Item&gt;
      &lt;Item&gt;
          &lt;id&gt;3&lt;/id&gt;
          &lt;name&gt;Example3&lt;/name&gt;
      &lt;/Item&gt;
  &lt;/Items&gt;
  </code></pre>
  
  <p>I'm able to load everything in and I see my data in the InnerXML but I cannot find out how to access it correctly.</p>
  
  <pre><code>public Form1()
      {
          InitializeComponent();
  
          assembly = Assembly.GetExecutingAssembly();
          XmlDocument xml = null;  
          try  
          {  
              string filePath = "MyProject.ItemList.xml";  
              Stream fileStream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filePath);  
              if (fileStream != null)  
              {  
                  xml = new XmlDocument();  
                  xml.Load(fileStream);  
              }  
          }  
          catch {   
              //Do nothing 
          }
  
          XmlDocument itemsFromXML =  xml.DocumentElement.InnerXml;
  
          foreach (XmlNode node in itemsFromXML)
          {
              int id = Convert.ToInt32(node.Attributes.GetNamedItem("id").ToString());
              string name = node.Attributes.GetNamedItem("name").ToString();
  
              gameItemList.Add(new GameItem(id, name));
          }
      }
  </code></pre>
  
  <p>That's the code I have that would ideally set this array up for me to use, though it is fairly broken due to me trying different things, but I think it conveys the general idea. Hopefully someone can make some sense of it and explain to me what I'm doing horribly wrong (>.&lt;) I would be happy to provide more information, clarification, etc if I missed something important!</p>
  
  <p>Thanks!</p>