title: TCL TDom: Looping through Objects
body: <p>Using TDom, I would like to cycle through a list of objects in the following format:</p>
  
  <pre><code>    &lt;object&gt;
        &lt;type&gt;Hardware&lt;/type&gt;
        &lt;name&gt;System Name&lt;/name&gt;
        &lt;description&gt;Basic Description of System.&lt;/description&gt;
        &lt;attributes&gt;
            &lt;vendor&gt;Dell&lt;/vendor&gt;
            &lt;contract&gt;MM/DD/YY&lt;/contract&gt;
            &lt;supportExpiration&gt;MM/DD/YY&lt;/supportExpiration&gt;
            &lt;location&gt;Building 123&lt;/location&gt;
            &lt;serial&gt;xxx-xxx-xxxx&lt;/serial&gt;
            &lt;mac&gt;some-mac-address&lt;/mac&gt;
        &lt;/attributes&gt;
      &lt;/object&gt;
  
      &lt;object&gt;
        &lt;type&gt;Software&lt;/type&gt;
        &lt;name&gt;Second Object&lt;/name&gt;
      ...
  </code></pre>
  
  <p>Then I use TDom to make a list of objects:</p>
  
  <pre><code>set dom [dom parse $xml]
  set doc [$dom documentElement]
  
  set nodeList [$doc selectNodes /systems/object]
  </code></pre>
  
  <p>So far I've done this to (theoretically) select every "Object" node from the list.  How can I loop through them?  Is it just:</p>
  
  <pre><code>foreach node $nodeList { 
  </code></pre>
  
  <p>For each object, I need to retrieve the association of each attribute.  From the example, I need to remember that the "name" is "System Name", "vendor" is "Dell", etc.</p>
  
  <p>I'm new to TCL but in other languages I would use an object or an associative list to store these.  Is this possible?  Can you show me an example of the syntax to select an attribute in this manner?</p>