Java 如何解组单个字符串元素(jaxb)?

Java 如何解组单个字符串元素(jaxb)?,java,xml,xsd,jaxb,Java,Xml,Xsd,Jaxb,这是我的xsd方案: <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://gov.com/oos/types/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="id" type="xs:int"/> <xs:element nam

这是我的xsd方案:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://gov.com/oos/types/1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="id" type="xs:int"/>
  <xs:element name="sum" type="xs:int"/>
  <xs:element name="docPublishDate" type="xs:dateTime"/>
  <xs:element name="href" type="xs:anyURI"/>
  <xs:element name="printForm">
    <xs:complexType>
      <xs:sequence>
        <xs:element type="xs:anyURI" name="url"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

我怎样才能得到一个名为“id”的元素?()

//我已经从xsd生成了类

JAXBContext jaxbContext = JAXBContext.newInstance(ObjectFactory.class);
            Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
            JAXBElement<int> jaxbElement = unmarshaller.unmarshal(source, ...
JAXBContext-JAXBContext=JAXBContext.newInstance(ObjectFactory.class);
Unmarshaller Unmarshaller=jaxbContext.createUnmarshaller();
JAXBElement=unmarshaller.unmarshal(源代码。。。

我不知道下一步该怎么做?如何获取基元类型值。Everywhere都会给我一个如何获取类复杂类型的指令?但不是像int或string这样的单个元素。请在
对象工厂中帮助
您可能有一个
id
JAXBElement
或类似的映射

所以你应该能够

JAXBElement<Integer> idElement = unmarshaller.unmarshal(source, ...);

方法如下:JAXBElement purchaseNumber=unmarshaller.unmarshal(source,Long.class | String.class);return me nill value.source url在ObjectFactory中设置正确,我只有以下内容:private final static QName(u Id)QName=new QName(“gov.com/oos/types/1”;“Id”)@xmlementdecl(namespace=“gov.com/oos/types/1”;,name=“Id”)public-JAXBElement-createId(Integer-value){返回新的JAXBElement(_-Id_-QNAME,Integer.class,null,value)}我知道我可以使用它将值设置为Id,但是当我试图解析xmlTry just
unmarshaller.unmarshal(source)
时,我不知道如何从源http url获取值。我能够执行JAXBElement-purchaseNumber=(JAXBElement)unmarshaller.unmarshal(源);这给了我一个错误JAXB error javax.xml.bind.UnmarshalException:意外的元素(uri:,local:“export”)。预期的元素是,,,,。。。
Integer id = idElement.getValue();