XML TRANSFORMATION

Description

Xmlt is xml transformer task that allow to:

Indentation

see: http://freemarker.org/docs/dgui_misc_whitespace.html

Xml task parameters


|Attribute  | Description           | Value                         | Required  |
|-----------|-----------------------|-------------------------------|-----------|
|file       | input file            | <filename>.xml                | yes       |
|tofile     | output file           | <filename>.<mime>             | yes       |
|template   | freemarker template   | <filename>.ftl                | yes       |
|overwrite  | overwrite output file | true by default               | no        |
                  

Exemple

Transform xml datas to sql.

users.xml

  • input file

<?xml version="1.0"?>
<users>
    <user login="foo" email="foo@mail.com"/>
    <user login="baz" email="baz@mail.com"/> 
</users>
                    

build.xml

  • ant file:

<project name="bidji-xmlt" xmlns:bj="antlib:org.bidji.taskdefs">
<target name="xml2sql" description=" transform xml datas to sql">       
    <bj:xmlt file="users.xml" tofile="users.sql" template="xml2sql.ftl"  overwrite="true"/>
</target>
</project>
                    

xml2sql.ftl

  • freemarker file

INSERT INTO table_users ( login, mail )
VALUES
[#foreach user in users.user]
( '${user.@login}', '${user.@email}' )[#if user?is_last];[#else],[/#if]
[/#foreach]
                    

users.sql

  • result file

INSERT INTO table_users ( login, mail )
VALUES
( 'foo', 'foo@mail.com' ),
( 'baz', 'baz@mail.com' );