Descriptor with default root element was not found in the project jaxb unmarshall
The problem was within the package-info.java class.
The package annotated with the XMLSchema
annotation that has the default namespace set to urn:kad:ns:file:1
, was not the same one used within the Root mapped object of the XML (Document).
So when the JAXB tries to unmarshall the XML, it cannot find the (Document) element in the package namespace since there is no namespace defined in the first place.
Document.java
package path.to.pkg.jaxbobjects;
....
package-info.java
@javax.xml.bind.annotation.XmlSchema(namespace =
"urn:kad:ns:file:1",
elementFormDefault =
javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package path.to.pkg.jaxbobjects2;
When removing the default namespace, this action is skipped and the file is allowed to be unmarshalled.
KAD
Software Engineer, working on banking applications. Along side, I work as a web designer/developer for multipurpose websites and applications providing multi services such as : Hosting and Domain, Database Analysis and Management, Business Applications, Mobile Applications, Technical Consultation, Graphic Design, Testing & Quality Control #SOreadytohelp ... Congrats everyone... Am always ready to help ;)
Updated on June 04, 2022Comments
-
KAD over 1 year
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?