I've just copied/pasted what you're doing and I get as an output:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="boo" xmlns:a="hoo">


which looks good. What version of xmltask are you using, and which VM ? Here's my ant -verbose output:

Apache Ant version 1.6.3 compiled on April 28 2005
Buildfile: build.xml
Detected Java version: 1.4 in: /usr/java/j2sdk1.4.2_07/jre
Detected OS: Linux
parsing buildfile /home/brian/projects/xmltask/samples/phale/build.xml with URI = file:///home/brian/projects/xmltask/samples/phale/build.xml
Project base dir set to: /home/brian/projects/xmltask/samples/phale
Build sequence for target(s) `main' is [main]
Complete build sequence is [main, ]

  [xmltask] Reading /home/brian/projects/xmltask/samples/phale/simple.xml
  [xmltask] Executing xmltask 1.10.7

re. your second question. You can disable schema validation by using XMLCatalog to point to an empty schema/DTD.


Pete Hale wrote:

I am trying to create a new xml file from scratch and having difficulty setting an attribute for the root element of the xml file.


I have as a source xml file:


<?xml version="1.0" encoding="UTF-8"?>




I want to add two attributes to the root element. The attribute names deal with xml namespace and are ‘xmlns’ and ‘xmlns:a’.


I am using the following xmltask definition to add these attributes:


        <xmltask source="simple.xml" dest="simple.out.xml" report="true">

           <attr path="/root" attr="xmlns" value="boo"/>

           <attr path="/root" attr="xmlns:a" value="hoo"/>



No errors are produced during the ant execution, however the attribute value for ‘xmlns’ was set to an empty string. The output file:


<?xml version="1.0" encoding="UTF-8"?>

<root xmlns="" xmlns:a="hoo">




What am I doing wrong?


One other question. Is there a way to disable schema/dtd validation?




Pete Hale



Join CEO Alfred Chuang and CTO Mark Carges on June 15 for a unique online 
event, giving you the first look at a new category of enterprise software 
built specifically for Service-Oriented Architecture (SOA).

Register Now.  It's Free!


<?xml version="1.0" encoding="UTF-8"?> <project name="xmlnserror" basedir="." default="error"> <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/> <target name="error"> <xmltask source="simple.xml" dest="simple.out.xml" report="true" failWithoutMatch="true" > <attr path="/root" attr="xmlns" value="boo"/> <attr path="/root" attr="xmlns:a" value="hoo"/> </xmltask> </target> </project>

<?xml version="1.0" encoding="UTF-8"?> <root> </root>

Brian Agnew                  http://www.oopsconsultancy.com
OOPS Consultancy Ltd         brian @ oopsconsultancy.com
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012