Dear Wiki user, You have subscribed to a wiki page or wiki category on "Ant Wiki" for change notification.
The following page has been changed by adebowale: http://wiki.apache.org/ant/AntNewbies ------------------------------------------------------------------------------ If you start a ''ant test'' you'll get no error. An ''ant -p'' just prints the ''generateImport'' and ''test'' target. After running a simple ''ant'' or ''ant generateImport'' the final ''ant -p'' will print all your written targets. + + Answer#17 I am having problems with nested elements + + {{{ + + <?xml version="1.0" encoding="ISO-8859-1"?> + <project name="BuildXmlUtilityTask" basedir="." default="buildXmlUtility"> + + <property name="src.dir" value="src"/> + <property name="classes.dir" value="classes"/> + + <target name="clean" description="Delete all generated files"> + <delete dir="${classes.dir}" failonerror="false"/> + <delete file="${ant.project.name}.jar"/> + </target> + + <target name="compile" description="Compiles the Task"> + <mkdir dir="${classes.dir}"/> + <javac srcdir="${src.dir}" destdir="${classes.dir}"/> + </target> + + <target name="jar" description="JARs the Task" depends="compile"> + <jar destfile="${ant.project.name}.jar" basedir="${classes.dir}"/> + </target> + + + <target name="buildXmlUtility" + description="Taskdef the BuildXmlUtitily-Task" + depends="jar"> + <taskdef name="buildUtility" + classname="com.corizon.xmlutility.XmlReaderUtility" + classpath="${ant.project.name}.jar"/> + <buildUtility> + <Argument arg = "C:\\project.xml"/> + <Argument arg ="/projects/project[1]/@id"/> + <Argument arg = "Id17000"/> + </buildUtility> + </target> + + </project> + + + + package com.corizon.xmlutility; + + import java.util.Iterator; + import java.util.Vector; + import org.apache.tools.ant.Task; + import org.apache.tools.ant.BuildException; + + + + public class XmlReaderUtility extends Task{ + + private static XmlFileReader xmlFileReader; + private String filePath; + private String xpathExpression; + private String value; + Vector arguments = new Vector(); + + + + public void setFilePath(String filePath) { + this.filePath = filePath; + } + + public void setXpathExpression(String xpathExpression) { + this.xpathExpression = xpathExpression; + } + + public void setValue(String value) { + this.value = value; + } + + /** Support for nested text. */ + public void addArgument(Argument text) { + arguments.add(text); + } + + + // The method executing the task + public void execute() throws BuildException { + int i = 0; + // handle nested elements + for (Iterator it = arguments.iterator(); it.hasNext(); ) + { + Argument arg = (Argument)it.next(); + if(i== 0) + { + setFilePath(arg.getArg()); + i++; + } + if(i==1) + { + setXpathExpression(arg.getArg()); + i++; + } + if(i==2) + { + setValue(arg.getArg()); + i++; + } + } + xmlFileReader = new XmlFileReader(filePath,xpathExpression,value); + } + + + /** A nested 'argument'. */ + public class Argument + { + // Bean constructor + public Argument() {} + + /** Argument to pass on. */ + String arg; + public void setArg(String arg) { this.arg = arg; } + public String getArg() { return arg; } + } + + + } + }}} + + It complains The <buildUtility> type doesn't support the nested "Argument' element + --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]