XJC will not generate @XmlElement with namespace?

I want to analyze data using JAXB for the following XSD scheme http://www.uniprot.org/support/docs/uniprot.xsd .

Typical XML for this is as follows: http://www.uniprot.org/uniprot/Q8NEJ9.xml

My classes were generated using:

xjc http://www.uniprot.org/support/docs/uniprot.xsd 

I can not get JMXB unmarshaller to analyze this data.

  xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); XMLEventReader rx=xmlInputFactory.createXMLEventReader(in); final QName uEntry=new QName("http://uniprot.org/uniprot","entry"); while(rx.hasNext()) { XMLEvent evt=rx.peek(); if(!(evt.isStartElement() && evt.asStartElement().getName().equals(uEntry))) { rx.next(); continue; } JAXBElement<Entry> jaxbElement=uniprotUnmarshaller.unmarshal(rx, Entry.class); Entry entry= jaxbElement.getValue(); (...) } 

Each entry entry is left blank. When a record is marshaled in stderr, I get something like:

 <ns2:entry xmlns:ns2="http://uniprot.org/uniprot" dataset="Swiss-Prot" created="2011-06-28+01:00" modified="2011-09-21+01:00" version="20"/> 

I think because xjc ignores namespaces. It generates:

 @XmlRootElement(name = "entry") public class Entry { 

instead of (?)

 @XmlRootElement(name = "entry",namespace="http://uniprot.org/uniprot") public class Entry { 

How can i fix this?

+4
source share
1 answer

Class A package-info containing the @XmlSchema annotation will be created for you. Since a namespace was specified along with elementFormDefault to XmlNsForm.QUALIFIED , all annotations matching XML elements without the specified namespace parameter will belong to this namespace.

 // // This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.4 // See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> // Any modifications to this file will be lost upon recompilation of the source schema. // Generated on: 2013.07.22 at 10:14:54 AM EDT // @javax.xml.bind.annotation.XmlSchema(namespace = "http://uniprot.org/uniprot", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.uniprot.uniprot; 

Additional Information

+6
source

Source: https://habr.com/ru/post/1492718/


All Articles