TCL TDom: Looping through Objects
- by pws5068
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?