title: Parsing XML with more than one element
body: <p>I am finding it difficult to parse the below xml structure (using c#.net 4.5) and store in the DB (Sql-Server). </p>
  
  <p>I know how to parse as long as there is one attribute of each record e.g. Publisher; Date(Year) but as you see from the structure within authors there is more than one, which is where I am struggling.</p>
  
  <p>I use XmlNodeList, XmlNode and InnerText to extract the data from each element. </p>
  
  <p>Appreciate your time and assistance</p>
  
  <p><strong>XML Structure</strong></p>
  
  <pre><code>&lt;Books&gt;
    &lt;Book&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;date&gt;
        &lt;year&gt;&lt;/year&gt;
      &lt;/date&gt;
      &lt;Link&gt;&lt;/link&gt;
      &lt;summary&gt;&lt;/summary&gt;
      &lt;publisher&gt;
        &lt;name&gt;&lt;/name&gt;
      &lt;/publisher&gt;
      &lt;authors total="2"&gt;
        &lt;author&gt;
          &lt;name&gt;&lt;/name&gt;
        &lt;/author&gt;
        &lt;author&gt;
          &lt;name&gt;&lt;/name&gt;
        &lt;/author&gt;
      &lt;/authors&gt;
    &lt;/Book&gt;
  &lt;/Books&gt;
  </code></pre>
  
  <p>I have now attached the code that I am using which works fine except  (because of it having more than one attribute unlike others)</p>
  
  <pre><code>XmlDocument xml = new XmlDocument();
                  xml.LoadXml(/*Here I pass the xml which has been stored in string variable. The structure of which has been in my original post*/);
                  XmlNodeList xnList = xml.SelectNodes("/Books[@*]");
                  foreach (XmlNode xn in xnList)
                  {
                      XmlNodeList anodes = xn.SelectNodes("Book");
                      foreach (XmlNode node in anodes)
                      {
                          if (anodes != null)
                          {
                              titles.Add(node["title"].InnerText);  //titles is an list
                              summarys.Add(node["summary"].InnerText);//Summarys is an list
                              link.Add(node["Link"].InnerText);//link is an list
                              counter +=1;
                                  }
                        }
                              XmlNodeList CNodes = xn.SelectNodes("Book");
                              foreach (XmlNode node2 in CNodes)
                              {
                                  XmlNode example = node2.SelectSingleNode("date");
                                  if (example != null)
                                  {
                                      years.Add(example["year"].InnerText);//years is an list
                                  }
                              }
                              XmlNodeList dNodes = xn.SelectNodes("Book");
                              foreach (XmlNode node3 in dNodes)
                              {
                                  XmlNode example1 = node3.SelectSingleNode("publisher");
                                  if (example1 != null)
                                  {
                                      publishers.Add(example1["name"].InnerText);//publishers is an list
                                  }
                              }
  
                             XmlNodeList fnodes = xn.SelectNodes("Book/authors/author/name");
                                  foreach (XmlNode node5 in fnodes)
                                  {
  
                                      authors.Add( node5 != null ? node5.InnerText : "");//authors is an list. For the first book i need to store in list[0] and next in list[1]
  
                                      }
                              }
          // Convert list to array
                              titles.ToArray();
                              summarys.ToArray();
                              urls.ToArray();
                              years.ToArray();
                              publishers.ToArray();
                              authors.ToArray();
  </code></pre>