You are viewing a plain text version of this content. The canonical link for it is here.
Posted to rivet-dev@tcl.apache.org by mx...@apache.org on 2012/09/29 19:11:41 UTC
svn commit: r1391842 - in /tcl/rivet/trunk: ChangeLog rivet/rivet-tcl/xml.tcl
Author: mxmanghi
Date: Sat Sep 29 17:11:41 2012
New Revision: 1391842
URL: http://svn.apache.org/viewvc?rev=1391842&view=rev
Log:
* rivet/rivet-tcl/xml.tcl: Adding command for simple quick XML fragments generation
Added:
tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl
Modified:
tcl/rivet/trunk/ChangeLog
Modified: tcl/rivet/trunk/ChangeLog
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/ChangeLog?rev=1391842&r1=1391841&r2=1391842&view=diff
==============================================================================
--- tcl/rivet/trunk/ChangeLog (original)
+++ tcl/rivet/trunk/ChangeLog Sat Sep 29 17:11:41 2012
@@ -1,3 +1,6 @@
+2012-09-29 Massimo Manghi <mx...@apache.org>
+ * rivet/rivet-tcl/xml.tcl: Adding command for simple quick XML fragments generation
+
2012-09-22 Massimo Manghi <mx...@apache.org>
* rivet/packages/dio/dio.tcl: various methods used as
accessors to some property variables of the class Database were not returning their values
Added: tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl
URL: http://svn.apache.org/viewvc/tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl?rev=1391842&view=auto
==============================================================================
--- tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl (added)
+++ tcl/rivet/trunk/rivet/rivet-tcl/xml.tcl Sat Sep 29 17:11:41 2012
@@ -0,0 +1,51 @@
+#
+# xml.tcl string ?tag ?attr val? ?attr val?? ?tag ?attr val? ?attr val??
+#
+# Example 1:
+#
+# ::rivet::xml Test b i -> <b><i>Test</i></b>
+#
+# Example 2:
+#
+# ::rivet::xml Test [list div class box id testbox] b i
+#
+# -> <div class="box" id="testbox"><b><i>Test</i></b></div>
+#
+# Example 3
+#
+# set d [list div [list a 1 b 2] b [list c 3 d 4] i [list e 5 f 6]]
+# ::rivet::xml Test {*}$d
+#
+# -> <div a="1" b="2"><b c="3" d="4"><b c="3" d="4"><i e="5" f="6">Test</i></b></div>
+#
+# $Id: $
+#
+
+namespace eval ::rivet {
+
+ proc xml {textstring args} {
+
+ set xmlout ""
+ set tags_stack {}
+
+ foreach el $args {
+
+ set tag [lindex $el 0]
+ set tags_stack [linsert $tags_stack 0 $tag]
+ append xmlout "<$tag"
+
+ if {[llength $el] > 1} {
+
+ foreach {attrib attrib_v} [lrange $el 1 end] {
+ append xmlout " $attrib=\"$attrib_v\""
+ }
+
+ }
+
+ append xmlout ">"
+ }
+
+ append xmlout "$textstring</[join $tags_stack ></]>"
+
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-cvs-unsubscribe@tcl.apache.org
For additional commands, e-mail: rivet-cvs-help@tcl.apache.org