I want to parse data using JAXB for the the following XSD schema http://www.uniprot.org/support/docs/uniprot.xsd .
A typical XML for this looks like this: http://www.uniprot.org/uniprot/Q8NEJ9.xml
My Classes were generated using:
xjc http://www.uniprot.org/support/docs/uniprot.xsd
I cannot get a JAXB unmarshaller to parse 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 instance of 'entry' remains empty. When an entry is marshaled to 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 it's because xjc ignores the 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 ?