title: Read XML File VB.NET
body: <p>I'm trying to read the following XML file in VB.NET</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;mame build="0.129 (Jan  8 2009)" debug="no"&gt;
      &lt;game name="puckman" sourcefile="pacman.c"&gt;
          &lt;description&gt;PuckMan (Japan set 1, Probably Bootleg)&lt;/description&gt;
          &lt;year&gt;1980&lt;/year&gt;
          &lt;manufacturer&gt;Namco&lt;/manufacturer&gt;
          &lt;rom name="namcopac.6e" size="4096" crc="fee263b3" sha1="87117ba5082cd7a615b4ec7c02dd819003fbd669" region="main" offset="0"/&gt;
          &lt;rom name="namcopac.6f" size="4096" crc="39d1fc83" sha1="326dbbf94c6fa2e96613dedb53702f8832b47d59" region="main" offset="1000"/&gt;
          &lt;rom name="namcopac.6h" size="4096" crc="02083b03" sha1="7e1945f6eb51f2e51806d0439f975f7a2889b9b8" region="main" offset="2000"/&gt;
          &lt;rom name="namcopac.6j" size="4096" crc="7a36fe55" sha1="01b4c38108d9dc4e48da4f8d685248e1e6821377" region="main" offset="3000"/&gt;
          &lt;rom name="pacman.5e" size="4096" crc="0c944964" sha1="06ef227747a440831c9a3a613b76693d52a2f0a9" region="gfx1" dispose="yes" offset="0"/&gt;
          &lt;rom name="pacman.5f" size="4096" crc="958fedf9" sha1="4a937ac02216ea8c96477d4a15522070507fb599" region="gfx1" dispose="yes" offset="1000"/&gt;
          &lt;rom name="82s123.7f" size="32" crc="2fc650bd" sha1="8d0268dee78e47c712202b0ec4f1f51109b1f2a5" region="proms" offset="0"/&gt;
          &lt;rom name="82s126.4a" size="256" crc="3eb3a8e4" sha1="19097b5f60d1030f8b82d9f1d3a241f93e5c75d6" region="proms" offset="20"/&gt;
          &lt;rom name="82s126.1m" size="256" crc="a9cc86bf" sha1="bbcec0570aeceb582ff8238a4bc8546a23430081" region="namco" offset="0"/&gt;
          &lt;rom name="82s126.3m" size="256" crc="77245b66" sha1="0c4d0bee858b97632411c440bea6948a74759746" region="namco" offset="100"/&gt;
          &lt;chip type="cpu" tag="main" name="Z80" clock="3072000"/&gt;
          &lt;chip type="audio" tag="namco" name="Namco" clock="96000"/&gt;
          &lt;display type="raster" rotate="90" width="288" height="224" refresh="60.606061" pixclock="6144000" htotal="384" hbend="0" hbstart="288" vtotal="264" vbend="0" vbstart="224" /&gt;
          &lt;sound channels="1"/&gt;
          &lt;input players="2" buttons="1" coins="2" service="yes"&gt;
              &lt;control type="joy4way"/&gt;
          &lt;/input&gt;
          &lt;dipswitch name="Rack Test (Cheat)"&gt;
              &lt;dipvalue name="Off" default="yes"/&gt;
              &lt;dipvalue name="On"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Service Mode"&gt;
              &lt;dipvalue name="Off" default="yes"/&gt;
              &lt;dipvalue name="On"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Cabinet"&gt;
              &lt;dipvalue name="Upright" default="yes"/&gt;
              &lt;dipvalue name="Cocktail"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Coinage"&gt;
              &lt;dipvalue name="2 Coins/1 Credit"/&gt;
              &lt;dipvalue name="1 Coin/1 Credit" default="yes"/&gt;
              &lt;dipvalue name="1 Coin/2 Credits"/&gt;
              &lt;dipvalue name="Free Play"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Lives"&gt;
              &lt;dipvalue name="1"/&gt;
              &lt;dipvalue name="2"/&gt;
              &lt;dipvalue name="3" default="yes"/&gt;
              &lt;dipvalue name="5"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Bonus Life"&gt;
              &lt;dipvalue name="10000" default="yes"/&gt;
              &lt;dipvalue name="15000"/&gt;
              &lt;dipvalue name="20000"/&gt;
              &lt;dipvalue name="None"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Difficulty"&gt;
              &lt;dipvalue name="Normal" default="yes"/&gt;
              &lt;dipvalue name="Hard"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Ghost Names"&gt;
              &lt;dipvalue name="Normal" default="yes"/&gt;
              &lt;dipvalue name="Alternate"/&gt;
          &lt;/dipswitch&gt;
          &lt;driver status="good" emulation="good" color="good" sound="good" graphic="good" savestate="supported" palettesize="512"/&gt;
      &lt;/game&gt;
      &lt;game name="puckmana" sourcefile="pacman.c" cloneof="puckman" romof="puckman"&gt;
          &lt;description&gt;PuckMan (Japan set 2)&lt;/description&gt;
          &lt;year&gt;1980&lt;/year&gt;
          &lt;manufacturer&gt;Namco&lt;/manufacturer&gt;
          &lt;rom name="pacman.6e" size="4096" crc="c1e6ab10" sha1="e87e059c5be45753f7e9f33dff851f16d6751181" region="main" offset="0"/&gt;
          &lt;rom name="pacman.6f" size="4096" crc="1a6fb2d4" sha1="674d3a7f00d8be5e38b1fdc208ebef5a92d38329" region="main" offset="1000"/&gt;
          &lt;rom name="pacman.6h" size="4096" crc="bcdd1beb" sha1="8e47e8c2c4d6117d174cdac150392042d3e0a881" region="main" offset="2000"/&gt;
          &lt;rom name="prg7" size="2048" crc="b6289b26" sha1="d249fa9cdde774d5fee7258147cd25fa3f4dc2b3" region="main" offset="3000"/&gt;
          &lt;rom name="prg8" size="2048" crc="17a88c13" sha1="eb462de79f49b7aa8adb0cc6d31535b10550c0ce" region="main" offset="3800"/&gt;
          &lt;rom name="chg1" size="2048" crc="2066a0b7" sha1="6d4ccc27d6be185589e08aa9f18702b679e49a4a" region="gfx1" dispose="yes" offset="0"/&gt;
          &lt;rom name="chg2" size="2048" crc="3591b89d" sha1="79bb456be6c39c1ccd7d077fbe181523131fb300" region="gfx1" dispose="yes" offset="800"/&gt;
          &lt;rom name="pacman.5f" merge="pacman.5f" size="4096" crc="958fedf9" sha1="4a937ac02216ea8c96477d4a15522070507fb599" region="gfx1" dispose="yes" offset="1000"/&gt;
          &lt;rom name="82s123.7f" merge="82s123.7f" size="32" crc="2fc650bd" sha1="8d0268dee78e47c712202b0ec4f1f51109b1f2a5" region="proms" offset="0"/&gt;
          &lt;rom name="82s126.4a" merge="82s126.4a" size="256" crc="3eb3a8e4" sha1="19097b5f60d1030f8b82d9f1d3a241f93e5c75d6" region="proms" offset="20"/&gt;
          &lt;rom name="82s126.1m" merge="82s126.1m" size="256" crc="a9cc86bf" sha1="bbcec0570aeceb582ff8238a4bc8546a23430081" region="namco" offset="0"/&gt;
          &lt;rom name="82s126.3m" merge="82s126.3m" size="256" crc="77245b66" sha1="0c4d0bee858b97632411c440bea6948a74759746" region="namco" offset="100"/&gt;
          &lt;chip type="cpu" tag="main" name="Z80" clock="3072000"/&gt;
          &lt;chip type="audio" tag="namco" name="Namco" clock="96000"/&gt;
          &lt;display type="raster" rotate="90" width="288" height="224" refresh="60.606061" pixclock="6144000" htotal="384" hbend="0" hbstart="288" vtotal="264" vbend="0" vbstart="224" /&gt;
          &lt;sound channels="1"/&gt;
          &lt;input players="2" buttons="1" coins="2" service="yes"&gt;
              &lt;control type="joy4way"/&gt;
          &lt;/input&gt;
          &lt;dipswitch name="Rack Test (Cheat)"&gt;
              &lt;dipvalue name="Off" default="yes"/&gt;
              &lt;dipvalue name="On"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Service Mode"&gt;
              &lt;dipvalue name="Off" default="yes"/&gt;
              &lt;dipvalue name="On"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Cabinet"&gt;
              &lt;dipvalue name="Upright" default="yes"/&gt;
              &lt;dipvalue name="Cocktail"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Coinage"&gt;
              &lt;dipvalue name="2 Coins/1 Credit"/&gt;
              &lt;dipvalue name="1 Coin/1 Credit" default="yes"/&gt;
              &lt;dipvalue name="1 Coin/2 Credits"/&gt;
              &lt;dipvalue name="Free Play"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Lives"&gt;
              &lt;dipvalue name="1"/&gt;
              &lt;dipvalue name="2"/&gt;
              &lt;dipvalue name="3" default="yes"/&gt;
              &lt;dipvalue name="5"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Bonus Life"&gt;
              &lt;dipvalue name="10000" default="yes"/&gt;
              &lt;dipvalue name="15000"/&gt;
              &lt;dipvalue name="20000"/&gt;
              &lt;dipvalue name="None"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Difficulty"&gt;
              &lt;dipvalue name="Normal" default="yes"/&gt;
              &lt;dipvalue name="Hard"/&gt;
          &lt;/dipswitch&gt;
          &lt;dipswitch name="Ghost Names"&gt;
              &lt;dipvalue name="Normal" default="yes"/&gt;
              &lt;dipvalue name="Alternate"/&gt;
          &lt;/dipswitch&gt;
          &lt;driver status="good" emulation="good" color="good" sound="good" graphic="good" savestate="supported" palettesize="512"/&gt;
      &lt;/game&gt;
  &lt;/mame&gt;
  </code></pre>
  
  <p><strong>This is the code that i use</strong></p>
  
  <pre><code>Imports System.IO
  Imports System.Xml
  Public Class Form1
  
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Try
          Dim m_xmld As XmlDocument
          Dim m_nodelist As XmlNodeList
          Dim m_node As XmlNode
  
          m_xmld = New XmlDocument()
          m_xmld.Load("C:\mame2.xml")
          m_nodelist = m_xmld.SelectNodes("/mame/game")
  
          For Each m_node In m_nodelist
  
              Dim GameAttribute = m_node.Attributes.GetNamedItem("name").Value
              Dim name = m_node.ChildNodes.Item(0).InnerText
              Dim description = m_node.ChildNodes.Item(1).InnerText
              Dim manufacturer = m_node.ChildNodes.Item(2).InnerText
              Dim rotate = m_node.ChildNodes.Item(15).Attributes.GetNamedItem("rotate").Value
              Dim controles = m_node.ChildNodes.Item(17).ChildNodes.Item(0).Attributes.GetNamedItem("type").Value
  
              MessageBox.Show("ROM: " &amp; GameAttribute _
                &amp; "-- Description: " &amp; name &amp; "-- Year: " _
                &amp; description &amp; "-- Manufacturer: " _
                &amp; manufacturer &amp; "-- Rotate: " _
                &amp; rotate &amp; "-- Control Type: " &amp; controles)
  
          Next
      Catch errorVariable As Exception
  
          MessageBox.Show(errorVariable.ToString())
      End Try
      Me.Close()
  End Sub
  End Class
  </code></pre>
  
  <hr>
  
  <p>I'm trying to read "name", "description","year", "manufacturer", "rotate" and "input player control type".</p>
  
  <p>With this code  i can read the first game, but not the rest of XML file (in this example I paste 2 games). I can read the Childnodes and atributes by the childnode number, the problem is that the games in "rom" has different number of childnodes and the program returns me an error.</p>
  
  <p>I imagine there's another way to read this document, but I don't know which is it.</p>
  
  <p>Thanks for advance and sorry for my english.</p>