From: Smith, T. <ts...@sa...> - 2004-02-27 20:03:28
|
I am trying to get the attribute values in an xml document using tclxml. I can get the first name of an attribute in a tag, but cannot get the value for it, or the name-value pairs for the successive attributes. Here is my sample code: # -*- Tcl -*- package require xml set szStartTag "" set cnt 0 set countAttributesOnly 1 proc EStart2 {tagName attrList args} { global result countAttributesOnly if {![llength $attrList] && !$countAttributesOnly} { if {[info exists result($tagName)]} { set count 0 while {[info exists result($tagName/[incr count])]} {} set result($tagName/$count) {} } else { set result($tagName) {} } return {} } foreach {name value} $attrList { if {[info exists result($tagName,$name)]} { set count 0 while {[info exists result($tagName,$name,[incr count])]} {} set result($tagName,$name,$count) $value puts "tagName: $tagName Attname: $name count: $count Attvalue: $value" } else { set result($tagName,$name) $value puts "tagName: $tagName Attname: $name Attvalue: $value" } } } proc CData {data args} { global cnt if {![regexp {^[\t\r\n]+$} $data]} { puts "data: $data" incr cnt } return } proc PerformXmlActions { } { set p [xml::parser -elementstartcommand EStart2 \ -characterdatacommand CData] set mystream "<?xml version='1.0'?><Simulations><Simulation><Script/><ItemClasses><ItemClass Name='Sphere' Source='none' SuperClasses='none'><Script/></ItemClass><ItemClass Name='Cone'><Script/></ItemClass></ItemClasses><Sphere Radius='1'> <Script/></Sphere><Cone Radius='1' Height='2'><Script/></Cone></Simulation></Simulations>" $p parse $mystream return } PerformXmlActions ******************************** Here is the output I get from running this: tagName: ItemClass name: Name value: tagName: Script name: Name value: in info exists tagName: ItemClass name: Name count: 1 value: in info exists tagName: Script name: Name count: 1 value: tagName: Sphere name: Radius value: tagName: Script name: Radius value: tagName: Cone name: Radius value: in info exists tagName: Script name: Radius count: 1 value: ********************************* None of my attributes have values. I have tcl8.4 and tclxml 3.0. Any suggestions are appreciated. |