From: Mats B. <ma...@pr...> - 2001-06-12 16:15:24
|
Hi, If there is an entity to be expanded in character data, and if this entity is embraced, as in: <body>.can create text 10 10 -text {Hello "new World"}</body> the resulting parsed character data is not a well formed tcl expression anymore. The result is: % $myParser parse $data6 Element start ==> stream Character data ==> Element start ==> body Character data ==> .can create text 10 10 -text \{Hello } Character data ==> " Character data ==> new World Character data ==> " Character data ==> \ Element end ==> body Character data ==> Element end ==> stream % If assembling the ch data we get: .can create text 10 10 -text \{Hello }"new World"\ which is not a well formed tcl expression. I think the reason is that the character data callbacks are split up so that entities are reported alone. When tcl handles an open braced structure, it starts to insert backslashes in a number of places. Somehow this is not robust, and results in the result above. Yes, entity parsing can be switched off by -defaultexpandinternalentities 0 which works (though no entity parsing). Having tcl code like this is not an example of good structure, and is only to get things up running fast. The code was: package require xml proc HandleStart {name attlist} { if {[llength $attlist] > 0} { puts stderr "Element start ==> $name has attributes $attlist" } else { puts stderr "Element start ==> $name" } } proc HandleEnd {name} { puts stderr "Element end ==> $name" } proc HandleText {data} { puts stderr "Character data ==> $data" } set data6 {<stream><body>.can create text 10 10 -text {Hello "new World"}</body></stream>} set myParser [xml::parser] $myParser configure -elementstartcommand HandleStart \ -ignorewhitespace 1 \ -elementendcommand HandleEnd -characterdatacommand HandleText $myParser parse $data6 /Mats |