users@jaxb.java.net

xmlns attribute added to the root element after marshalling

From: Marcos <marcos_at_softingsystems.com.br>
Date: Fri, 19 Jan 2007 11:37:32 -0300

Hi all,

I'm facing a very interesting question ...
When I marshall my classes the xmlns is being printed as an attribute
with the root element (loaderJob) such as.:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<loaderJob xmlns="http://www.objectweb.org"
pathToLoggerConf="log4j.properties">
    <!-- Body omitted for brevity -->
</loaderJob>

This xml file was based on the following schema.:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.objectweb.org" <!-- Here is the little devil ;-) -->
    targetNamespace="http://www.objectweb.org"
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    jaxb:version="2.0"
    jaxb:extensionBindingPrefixes="xjc">
    <xs:element name="loaderJob">
        <xs:complexType>
            <xs:attribute name="pathToLoggerConf" type="xs:string"
use="optional"/>
            <!-- Other attributes/elements omitted for brevity -->
        </xs:complexType>
    </xs:element>
</xs:schema>

The presence of this xmlns attribute (xmlns="http://www.objectweb.org")
in my root element causes me some problems ;-(
Question.: How can I suppress this attribute in the xml obtained through
the marshalling process ?

Desired result.:
------------------------------------------
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<loaderJob pathToLoggerConf="log4j.properties"> <!-- Little devil
removed ;-) I just can't figure out how ;-( -->
    <!-- Body omitted for brevity -->
</loaderJob>

Code used to generate the marshalled xml
------------------------------------------
ByteArrayOutputStream ret = new ByteArrayOutputStream();
JAXBContext context =JAXBContext.newInstance("com.softing.etl.beans");
// Package of the beans generated by xjc
javax.xml.bind.Marshaller marsh = context.createMarshaller();
ObjectFactory of = new ObjectFactory();
/* ObjectFactory creation routines and object feeding */
marsh.marshal(loaderjob, ret);
System.out.println(ret); // Here I can see the xmlns that I've mentioned ;-(

Thank you very much
Marcos