I have the root element in my xml file as follows:
<Document xmlns="urn:kad:ns:file:1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
and the XSD header is as follows:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="urn:kad:ns:file:1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
When I try to unmarshal the file :
JAXBContext jc = JAXBContext.newInstance("path.to.package.of.schema.objects");
Unmarshaller u = jc.createUnmarshaller();
// read the file stream and unmarshall the XML
File f = new File(xmlFilePath);
Document document = (Document)u.unmarshal(f);
am getting the following exception:
Exception [EclipseLink-25008] (Eclipse Persistence Services - 2.1.3.v20110304-r9073): org.eclipse.persistence.exceptions.XMLMarshalException Exception Description: A descriptor with default root element {urn:kad:ns:file:1}Document was not found in the project
Is this something specific for having a urn as the target namespace in the XSD or am I missing something in the JAVA file unmarshalling the XML file?
Edit
When I remove the default namespace declaration form the xml file xmlns="urn:kad:ns:file:1"
, the unmarshal process works fine. But no validation occurs, meaning if I remove a required element from the XML, the process will continue at JAVA level and consider this element mapped object as null.
I was wondering what affect does this (the default namespace attribute in root element) have on the unmarshalling process? Does it instantly validate the XML against the XSD at the URN am specifying (which I suspect it is not finding in my case) ?
How can I validate the XML when unmarshalling agaisnt the XSD I have?
Document
element? – lexicore<xs:element name="Document">...</xs:element>
, but am suspecting that when jaxb is unmarshalling, it is not finding the schema and considering it as not in project.. Is this ture? Please check the edit – KADObjectFactory
in your package? JAXB does not consider schema during marshalling/unmarshalling (only for validation, if configured). It only uses your annotated classes. There should be an@XmlRootElement
annotation somewhere or anObjectFactory
with@XmlElementDecl
. – lexicore@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "chargelog" }) @XmlRootElement(name = "Document")
. – KAD