[task] Xml transformation
Description
Xmlt is xml transformer task that allow to:
- read datas from xml file(s)
- process datas using freemarker templates
Indentation
see: http://freemarker.org/docs/dgui_misc_whitespace.html
Xml task parameters
Attribute | Description | Value | Required |
---|---|---|---|
file | input file | .xml | file or fileset |
tofile | output file | . | tofile or todir |
template | freemarker template | .ftl | yes (or inner template) |
overwrite | overwrite output file | true by default | no |
todir | output dir | no | |
ouputproperty | output property | no | |
extension | output extension (with fileset + todir) | no |
Element | Description | Value | Required |
---|---|---|---|
fileset | fileset element | no | |
template | inner template element | no | |
parameter | custom param value | <parameter name=”” value=”"/> | no |
Usages
Use cases
file2file | set2set | set2file | file2set | |
---|---|---|---|---|
xmlt | xml2csv | maven deps | ||
todo | ast2code (todo: js) | gen code |
- mysqldump2liquibase
Use case
- Transform maven pom.xml to single (plant)uml diagram, see: set2file example.
Set to set
Generates one output file per input file.
+---+ +---+
| | +---> | |
| | | |
+---+ +---+
+---+ +---+
| | +---> | |
| | | |
+---+ +---+
build.xml
<project name="bidji-xmlt" xmlns:bj="antlib:org.bidji.taskdefs">
<target name="set2set" description="gen 1 to 1">
<bj:xmlt todir="path/to/output/dir" template="xml2csv.ftl" overwrite="true" extension=".csv">
<fileset dir="path/to/input/dir">
<include name="*.xml"/>
</fileset>
</bj:xmlt>
</target>
</project>
Use case
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' );
–>