TCL TDom: Looping through Objects

Posted by pws5068 on Stack Overflow See other posts from Stack Overflow or by pws5068
Published on 2010-04-09T14:10:04Z Indexed on 2010/04/10 13:53 UTC
Read the original article Hit count: 406

Filed under:
|
|

Using TDom, I would like to cycle through a list of objects in the following format:

    <object>
      <type>Hardware</type>
      <name>System Name</name>
      <description>Basic Description of System.</description>
      <attributes>
          <vendor>Dell</vendor>
          <contract>MM/DD/YY</contract>
          <supportExpiration>MM/DD/YY</supportExpiration>
          <location>Building 123</location>
          <serial>xxx-xxx-xxxx</serial>
          <mac>some-mac-address</mac>
      </attributes>
    </object>

    <object>
      <type>Software</type>
      <name>Second Object</name>
    ...

Then I use TDom to make a list of objects:

set dom [dom parse $xml]
set doc [$dom documentElement]

set nodeList [$doc selectNodes /systems/object]

So far I've done this to (theoretically) select every "Object" node from the list. How can I loop through them? Is it just:

foreach node $nodeList { 

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.

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?

© Stack Overflow or respective owner

Related posts about tcl

Related posts about Xml