[JAXB] Cannot find the declaration of element
Bonjour à tous,
j'ai un petit (gros) souci d'utilisation de JAXB pour la manipulation de mes fichiers XML.
J'ai créé une XSD définissant l'ensemble de mes types, dont voici un extrait :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
<xsd:schema targetNamespace="http://www.mycompany.com/mynamespace" elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:myns="http://www.mycompany.com/mynamespace">
<xsd:complexType name="TProductProperties">
<xsd:sequence>
<xsd:choice>
<xsd:element name="emailBox" type="myns:TEmailBox" />
<xsd:element name="redirection" type="myns:TRedirection" />
</xsd:choice>
<xsd:element name="domain" type="myns:TDomain" minOccurs="0" maxOccurs="1" />
</xsd:sequence>
</xsd:complexType>
[...]
<xsd:element name="productProperties" type="myns:TProductProperties" />
</xsd:schema> |
J'ai ensuite généré mes classes JAXB sans souci (après vérification, le code a l'air correct), puis j'ai écrit un fichier XML à la main que j'ai fait validé de 3 façons différentes (Eclipse, JAXB validator et ma propre librairie de validation) sans aucun problème.
Cependant, au parsing JAXB, pour me transformer le fichier XML en classe, j'obtiens l'erreur suivante :
Code:
1 2 3 4 5 6 7 8 9
|
javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'myns:productProperties'.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:506)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:324)
at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:297)
[...] |
Voici le code que j'utilise :
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
JAXBContext jaxbContext = JAXBContext.newInstance(TPRoductProperties.class);
URL xsdURL = new URL(xsdUri);
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = schemaFactory.newSchema(xsdURL);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setSchema(schema);
Document xmlDocument = [...];
JAXBElement<TProductProperties> root = (JAXBElement<TProductProperties>) unmarshaller.unmarshal(xmlDocument); |
J'ai déjà bien épluché le Web à la recherche d'une solution (comme celle-ci), mais sans succès.
J'utilise Maven2 pour rapatrier les dépendances:
- javax.xml.bind:jaxb-api:2.2
- com.sun.xml.bind:jaxb-impl:2.1.9
Please help !
Merci par avance,
Thomas