# -*- ruby -*-
#
# Expanding a template with attributes.
#

require 'xtemplate'

data = {
  'members' => [
    {'name' => 'name1', 'age' => 21, '@uid' => 1},
    {'name' => 'name2', 'age' => 22, '@uid' => 2},
    {'name' => 'name3', 'age' => 23, '@uid' => 3},
  ],
}

text = <<EOF
<?xml version="1.0" encoding="EUC-JP"?>
<members>
  <member uid="0">
     <name>root</name>
     <age />
     <comment>This entry is already described in the template.</comment>
  </member>
  <member id="members">
     <name id="name" />
     <age id="age" />
     <comment>This entry is generated by xtemplate.</comment>
  </member>
</members>
EOF

t = XTemplate::XMLTemplate.new(text)
print(t.expand(data))
