JAXB 1.0 Problème avec les namespaces
Bonjour,
Dans le cadre du projet, des classes java ont été générées via la xsd suivante.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:order="urn:ean.ucc:order:2" xmlns:eanucc="urn:ean.ucc:2" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="urn:ean.ucc:order:2" version="2.6">
<xsd:annotation>
<xsd:documentation></xsd:documentation>
</xsd:annotation>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/AllowanceCharge.xsd"/>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/ErrorOrWarningList.xsd"/>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/MonetaryAmount.xsd"/>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/PartyIdentification.xsd"/>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/ResponseDocument.xsd"/>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/ResponseStatusList.xsd"/>
<xsd:import namespace="urn:ean.ucc:2" schemaLocation="../../ean.ucc/common/TradeItemIdentification.xsd"/>
<xsd:include schemaLocation="MultiShipmentOrder.xsd"/>
<xsd:include schemaLocation="OrderLogisticalInformation.xsd"/>
<xsd:include schemaLocation="SimpleOrderLineItem.xsd"/>
<xsd:complexType name="OrderModificationLineItemLevelType">
<xsd:sequence>
<xsd:element name="substituteItemIdentification" type="eanucc:TradeItemIdentificationType" minOccurs="0"/>
<xsd:element name="modifiedOrderInformation" type="order:SimpleOrderLineItemType"/>
<xsd:element name="shipmentDetail" type="order:ShipmentDetailType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="allowanceCharge" type="eanucc:AllowanceChargeType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="orderResponseReasonCode" type="eanucc:ErrorOrWarningListType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="backorderInformation" type="order:ShipmentDetailType" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="lineItemChangeIndicator" type="eanucc:ResponseStatusListType"/>
<xsd:attribute name="deliveryDateTime" type="xsd:dateTime"/>
<xsd:attribute name="originalOrderLineItemNumber">
<xsd:simpleType>
<xsd:restriction base="xsd:nonNegativeInteger">
<xsd:totalDigits value="6"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="OrderModificationType">
<xsd:sequence>
<xsd:element name="amendedDateTimeValue" type="order:OrderLogisticalDateGroupType" minOccurs="0"/>
<xsd:element name="orderModificationLineItemLevel" type="order:OrderModificationLineItemLevelType" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="allowanceCharge" type="eanucc:AllowanceChargeType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="OrderResponseType">
<xsd:complexContent>
<xsd:extension base="eanucc:ResponseDocumentType">
<xsd:sequence>
<xsd:element name="buyer" type="eanucc:PartyIdentificationType"/>
<xsd:element name="seller" type="eanucc:PartyIdentificationType"/>
<xsd:element name="orderModification" type="order:OrderModificationType" minOccurs="0"/>
<xsd:element name="totalMonetaryAmountOfOrderExcludingTaxes" type="eanucc:AmountType" minOccurs="0"/>
<xsd:element name="totalTax" type="eanucc:AmountType" minOccurs="0"/>
<xsd:element name="orderResponseReasonCode" type="eanucc:ErrorOrWarningListType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="orderResponse" type="order:OrderResponseType"/>
</xsd:schema> |
En effectuant le unmarshall pour obtenir le flux xml, j'obtiens par ex :
Code:
1 2 3 4
|
<buyer xmlns="">
<gln>5412345000013</gln>
</buyer> |
J'aimerai ne pas avoir le xmlns = "". Est-ce possible ?
Effectivement dans le code généré par jaxb, on obtient cela dans une classe :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public void serializeBody(org.unece.cefact.namespaces.standardbusinessdocumentheader.impl.runtime.XMLSerializer context)
throws org.xml.sax.SAXException
{
int idx1 = 0;
final int len1 = ((_OrderResponseReasonCode == null)? 0 :_OrderResponseReasonCode.size());
super.serializeBody(context);
context.startElement("", "buyer");
context.childAsURIs(((com.sun.xml.bind.JAXBObject) _Buyer), "Buyer");
context.endNamespaceDecls();
context.childAsAttributes(((com.sun.xml.bind.JAXBObject) _Buyer), "Buyer");
context.endAttributes();
context.childAsBody(((com.sun.xml.bind.JAXBObject) _Buyer), "Buyer");
context.endElement(); |
Par défaut le uri est à "" ==> context.startElement("", "buyer");
Peut-on ne pas l'afficher ?
Est-il possible de déclarer tous les namespaces dans l'entête ? comme par ex :
Code:
1 2 3
| <?xml version="1.0" encoding="UTF-8"?>
<ns2:StandardBusinessDocument xmlns:ns2="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader" xmlns:ns3="urn:ean.ucc:2" xmlns:ns4="urn:ean.ucc:order:2" xmlns:ns5="urn:ean.ucc:deliver:2" xmlns:ns6="urn:ean.ucc:gdsn:2" xmlns:ns7="urn:ean.ucc:bdf:2" xmlns:ns8="http://www.w3.org/2000/09/xmldsig#" xmlns:ns9="http://uri.etsi.org/01903/v1.3.2#">
.... |
car actuellement dans les documents que je génère, le xmlns est toujours défini sur les balises .
Est-ce du à la version de jaxb ?
Merci d'avance.