title: Parse XML and get elements from it using C#
body: <p>I have an XML file such as below:</p>
  
  <pre><code>&lt;host&gt;
      &lt;status state="up" reason="arp-response" reason_ttl="0"/&gt;
      &lt;address addr="128.208.188.2" addrtype="ipv4"/&gt;
      &lt;address addr="00:19:D1:3D:65:85" addrtype="mac" vendor="Intel Corporate"/&gt;
      &lt;hostnames&gt;
          &lt;hostname name="d0slf4.phys.washington.edu" type="PTR"/&gt;
      &lt;/hostnames&gt;
      &lt;times srtt="1000" rttvar="5000" to="100000"/&gt;
  &lt;/host&gt;
  
  &lt;host&gt;
      &lt;status state="up" reason="arp-response" reason_ttl="0"/&gt;
      &lt;address addr="128.208.188.3" addrtype="ipv4"/&gt;
      &lt;address addr="3C:94:D5:AC:18:7D" addrtype="mac" vendor="Juniper Networks"/&gt;
      &lt;hostnames&gt;
          &lt;hostname name="xe-0-3-2-&amp;#45;1378.uwar-atg-1.infra.washington.edu" type="PTR"/&gt;
      &lt;/hostnames&gt;
      &lt;times srtt="92000" rttvar="92000" to="460000"/&gt;
  &lt;/host&gt;
  </code></pre>
  
  <p>The above code is a sample of two  objects in a large file. I'd like to get all the hosts in the file, and for each one, show it's name, ipv4 address, and vendor.</p>
  
  <p>I've been doing searching for the last hour, and while I've found some good examples, none of them fit exactly what I need (sorry I'm new to XML parsing).</p>
  
  <p>Here's the code I've been trying (incomplete, because I don't know where to go next):</p>
  
  <pre class="lang-cs prettyprint-override"><code>string path = ""\\thor\test$\DataSubnetScans\" + _readableSubnet + ".xml";
  
  XmlDocument xmlDoc = new XmlDocument();
  xmlDoc.Load(path);
  
  XmlNodeList hosts = xmlDoc.GetElementsByTagName("host");
  foreach (XmlNode host in hosts) 
  {
      // get elements (FQDN, IPv4, Vendor)
      XmlNodeList FQDN = this.GetElementsByTagName("hostname");
  }
  </code></pre>
  
  <p>The line of code inside the foreach loop is wrong, it was just a guess. As you can see above, I'm trying to create a list of all the  elements, and then for each one, grab the hostname name, ipv4 address, and the vendor.</p>
  
  <p>I understand that this is a little different than reading the text between the &lt;> tags, and so I have to use something like <code>Attributes["name"].Value</code>.</p>
  
  <p>I'm not sure if using <code>XmlNodeList</code> inside the foreach loop is the way to do this, but because each  element has 2  elements, I need a way to select them individually. Doing this should allow me to select the index right?</p>
  
  <p>Could someone help point me in the right direction?</p>
  
  <p>Thanks a bunch, and please let me know if you need additional information.</p>