Presented is an example of how to use Groovy AntBuilder to drive the use of
XMLTask to transform an XML file. In addition, shown is how to unit test using
the XMLUnit framework.
http://members.cox.net/jbetancourt1/content/GroovyAntXMLTaskXMLUnit.html
Basically, the Groovy AntBuilder reuses the Ant library and eliminates the use
of XML as a scripting language. XML doesn't bother me, but this approach
removes the "declaritive" straight jacket (allows procedural coding).
/**
* Example of using Groovy AntBuilder to invoke XMLTask via Ant API.
* @file Replace.groovy
* @author Josef Betancourt
* @date 20071205T23:14
*/
def SOURCE='data/storage.xml'
def DEST='target/storage-new.xml'
def XPATH='//[EMAIL PROTECTED]'widgetB\']/VALUE/@value'
def VALUE='Y'
def SYSTEM = 'classpath://some/path/to/dtd/narly.dtd'
def REMOTE = SYSTEM
def ant = new AntBuilder()
ant.sequential{
path(id: "path") {
fileset(dir: 'lib') {
include(name: "**/*.jar")
}
}
ant.taskdef(name:'xmltask',classname:
'com.oopsconsultancy.xmltask.ant.XmlTask',classpathref: 'path')
ant.xmltask(source:SOURCE,dest:DEST,expandEntityReferences:false,
report:false,system:SYSTEM){
entity(remote:REMOTE,local:'') // don't use DTD spec'd in DOCTYPE
replace(path:XPATH,withText:VALUE)
}
}
// end Replace.groovy script
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Xmltask-users mailing list
Xmltask-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xmltask-users