java如何解组单个字符串元素(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这样的单个元素。请帮忙
# 1 楼答案
在
ObjectFactory
中,可能有id
到JAXBElement<Integer>
或类似的映射所以你应该能够
然后