如何解组单个字符串元素 (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 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, ...

我不知道下一步该怎么做?如何获取基元类型值。到处给我一个指导如何获得类复杂类型?但不是像 int 或 string 这样的单个元素。请帮忙

在你的ObjectFactory中,你可能有一个idJAXBElement<Integer>或类似的映射。

所以你应该能够

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

然后

Integer id = idElement.getValue();

最新更新