Some piece of documentation (in JAXB_2_2/docs/vendorProperties.html) claims
that
this "lot of namespace declarations that look redundant to human eyes"
shouldn't
occur with JAXB RI 2.x, "mostly".
If you are using 2.x, then look into the namespacePrefixMapper described
there;
overriding getPredeclaredNamespaceUris ought to hekp,
-W
On 24 June 2010 03:40, Alex Wibowo <alexwibowo_at_gmail.com> wrote:
> Hi all,
>
>
> I currently have a base schema that looks like:
>
> ----------------------
> <xsd:schema
> targetNamespace="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/Event.xsd"
> xmlns="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/Event.xsd"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified"
> version="1">
> <xsd:complexType name="Event">
> <xsd:sequence>
> <xsd:element name="CreatedDateTime" type="xsd:dateTime"
> minOccurs="0">
> <xsd:annotation>
> <xsd:documentation>When this event was
> generated.</xsd:documentation>
> </xsd:annotation>
> </xsd:element>
> </xsd:complexType>
> </xsd:schema>
>
> ----------------------
>
>
> which is then extended by lots of other schema, e.g.:
>
> -----------------------
> <xsd:schema
> targetNamespace="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/DespatchB10FileEvent.xsd
> "
> xmlns="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/Event.xsd"
> xmlns:e="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/Event.xsd"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified"
> version="1">
>
> <xsd:import
> namespace="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/Event.xsd"
> schemaLocation="Event.xsd"/>
>
>
> <xsd:element name="DespatchB10FileEvent">
> <xsd:complexType>
> <xsd:complexContent>
> <xsd:extension base="e:Event">
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
> </xsd:element>
>
> </xsd:schema>
>
> -----------------------
>
> JAXB will compile the base class, generating something like:
> --------------------------
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "Event", propOrder = {
> "createdDateTime",
> "eventCreator"
> })
> @XmlSeeAlso({
> ReceiveDVJO2301FileEvent.class,
> ReceiveDVJO4803FileEvent.class,
> ReceiveDVJO4701FileEvent.class,
> ReceiveDVJL4501FileEvent.class,
> ReceiveDVJAXH01FileEvent.class,
> ReceiveDVJO8200FileEvent.class,
> ReceiveDVJO8001FileEvent.class,
> DespatchBSIFileEvent.class,
> DespatchB10FileEvent.class,
> .....
> })
> public class Event {
>
> @XmlElement(name = "CreatedDateTime")
> @XmlSchemaType(name = "dateTime")
> protected XMLGregorianCalendar createdDateTime;
>
> ....
>
> }
> --------------------------
>
>
> and for the subclass:
> ------------------------------
> @XmlAccessorType(XmlAccessType.FIELD)
> @XmlType(name = "")
> @XmlRootElement(name = "DespatchB10FileEvent")
> public class DespatchB10FileEvent
> extends Event{
>
>
> }
> ------------------------------
>
> This is all fine, except during the marshalling process, the result looks
> like :
>
> --------------------------------
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <ns7:DespatchB10FileEvent
> xmlns:ns42="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/ReceiveDVJO3301FileEvent.xsd
> "
> xmlns:ns5="
> http://webservices.nab.com.au/schema/nab/2009/09/03/FileRef.xsd"
> xmlns:ns6="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/Event.xsd"
> xmlns:ns7="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/DespatchB10FileEvent.xsd
> "
> xmlns:ns8="
> http://webservices.nab.com.au/schema/nab/event/2009/07/21/ReceiveDVJO1202FileEvent.xsd
> "
> xmlns:ns2="
> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd
> "
> xmlns:ns1="
> http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd
> "
> xmlns:ns4="
> http://webservices.nab.com.au/schema/nab/2005/02/18/Addressing.xsd"
> xmlns:ns3="http://schemas.xmlsoap.org/ws/2003/03/addressing"
> xmlns:ns207="http://www.w3.org/2003/05/soap-envelope"
> ....
> >
>
> <ns6:CreatedDateTime>2010-06-23T15:00:04.094+10:00</ns6:CreatedDateTime>
> </ns7:DespatchB10FileEvent>
> ---------------------------------
>
> i.e. the root element contains all the namespaces from the other
> subclasses.
>
> Clearly these other namespaces are not required for this particular
> message. Is there any way to get around this?
> By the way, I'm using maven JAXB plugin
> (org.jvnet.jaxb2.maven2.maven-jaxb2-plugin) 0.7.3 to compile the schema. But
> I dont think that is related to the issue I'm having...
>
> Also... the way I marshalled it was by doing:
>
> -------------------
>
> DespatchB10FileEvent b10FileEvent = new DespatchB10FileEvent();
> Marshaller marshaller =
> JAXBContext.newInstance(DespatchB10FileEvent.class).createMarshaller();
> marshaller.marshal(b10FileEvent, System.out);
>
> -------------------
>
>
> Thanks a lot for the help!
>
>
>
> --
> Best regards,
>
>
> WiB
>
>