Simple Example ---------------- Assume that the following XML document is a target document we generate. Foo 22 Bar We first prepare the following template 'text' and create a template object 'template'. text = < EOF require 'xtemplate' template = XTemplate::XMLTemplate.new(text) We then expand the template with the following data. data = { "members" => [ {"@uid" => "&001", "name" => "Foo", "age" => 22}, {"@uid" => "&002", "name" => "Bar"}, ] } doc = template.expand(data) puts(doc.to_s) Each '@uid' represents an attribute. All strings/objects in given data are automatically sanitized. 'doc' is a result of expanding the template. The following document is generated. Foo 22 Bar If you would like to pass sanitized strings/objects to xtemplate, use XTemplate::SanitizedString (See samples/sample1.rb). We can successively output strings using Template#expand2 as follows: template2 = XTemplate::XMLTemplate.new(text2) template2.expand2($stdout,data) The template object dumps generated strings using a method '<<'. Also, a given data is modified by an expansion. If you don't want to modify it, give options like this: template2.expand2($stdout,data, :keep_data => true) Namespace of XTemplate ----------------------- If you define a namespace with the URI "http://xtemplate.sourceforge.net/xtemplate", the following tags are available. -