Java XJC没有';是否生成具有命名空间的@XmlElement?

Java XJC没有';是否生成具有命名空间的@XmlElement?,java,jaxb,xsd,xjc,stax,Java,Jaxb,Xsd,Xjc,Stax,我想使用JAXB为以下XSD模式解析数据 这方面的典型XML如下所示: 我的类是使用以下方法生成的: xjc http://www.uniprot.org/support/docs/uniprot.xsd 我无法使用JAXB解组器来解析此数据 xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, Boolean.TRUE); XMLEventReader rx=xmlInputFactory.createXMLEv

我想使用JAXB为以下XSD模式解析数据

这方面的典型XML如下所示:

我的类是使用以下方法生成的:

xjc http://www.uniprot.org/support/docs/uniprot.xsd
我无法使用JAXB解组器来解析此数据

 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();
    (...) 
   }
而不是(?)


如何修复此问题?

将为您生成一个包含
@XmlSchema
注释的
包信息
类。由于
名称空间
elementFormDefault
一起指定,等于
XmlNsForm。限定的
与未指定名称空间参数的XML元素对应的所有注释都将属于此名称空间

//
// 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;
//
//该文件由JavaTM XML绑定体系结构(JAXB)参考实现v2.2.4生成
//看
//重新编译源架构时,对此文件的任何修改都将丢失。
//生成日期:2013.07.22美国东部时间上午10:14:54
//
@javax.xml.bind.annotation.XmlSchema(名称空间=”http://uniprot.org/uniprot,elementFormDefault=javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
包org.uniprot.uniprot;
了解更多信息


谢谢Blaise,我的ant路径中缺少package-info.java。我没想到这个文件会被编译。嗨,我有一个非常类似的问题。你到底要做什么才能让它工作?我确实有生成的
包信息
类,但我不确定如何“使用”它。我是否必须以某种方式将其添加到maven构建过程中?
@XmlRootElement(name = "entry")
public class Entry {
@XmlRootElement(name = "entry",namespace="http://uniprot.org/uniprot")
public class Entry {
//
// 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;