TCL tDom Empty XML Tag
Posted
by pws5068
on Stack Overflow
See other posts from Stack Overflow
or by pws5068
Published on 2010-04-14T19:14:34Z
Indexed on
2010/04/15
13:53 UTC
Read the original article
Hit count: 415
I'm using tDom to loop through some XML and pull out each element's text().
set xml {
<systems>
<object>
<type>Hardware</type>
<name>Server Name</name>
<attributes>
<vendor></vendor>
</attributes>
</object>
<object>
<type>Hardware</type>
<name>Server Two Name</name>
<attributes>
<vendor></vendor>
</attributes>
</object>
</systems>
};
set doc [dom parse $xml]
set root [$doc documentElement]
set nodeList [$root selectNodes /systems/object]
foreach node $nodeList {
set nType [$node selectNodes type/text()]
set nName [$node selectNodes name/text()]
set nVendor [$node selectNodes attributes/vendor/text()]
# Etc...
puts "Type: "
puts [$nType data]
# Etc ..
puts [$nVendor data]
}
But when it tries to print out the Vendor, which is empty, it thows the error invalid command name "". How can I ignore this and just set $nVendor to an empty string?
© Stack Overflow or respective owner