如何使用 jaxb 读取以下 xml?
<xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882'
xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882'
xmlns:rs='urn:schemas-microsoft-com:rowset'
xmlns:z='#RowsetSchema'>
<s:Schema id='RowsetSchema'>
<s:ElementType name='row' content='eltOnly' rs:updatable='true'>
<s:AttributeType name='ATCCode' rs:number='1' rs:nullable='true' rs:writeunknown='true' rs:basecatalog='ATC'
rs:basetable='#t1' rs:basecolumn='ATCCode'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='10'/>
</s:AttributeType>
<s:AttributeType name='DDD' rs:number='2' rs:nullable='true' rs:writeunknown='true' rs:basecatalog='ATC' rs:basetable='#t1'
rs:basecolumn='DDD'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='20'/>
</s:AttributeType>
<s:AttributeType name='UnitType' rs:number='3' rs:nullable='true' rs:writeunknown='true' rs:basecatalog='ATC'
rs:basetable='#t1' rs:basecolumn='UnitType'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='255'/>
</s:AttributeType>
<s:AttributeType name='AdmCode' rs:number='4' rs:nullable='true' rs:writeunknown='true' rs:basecatalog='ATC'
rs:basetable='#t1' rs:basecolumn='AdmCode'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='255'/>
</s:AttributeType>
<s:AttributeType name='DDDComment' rs:number='5' rs:nullable='true' rs:writeunknown='true' rs:basecatalog='ATC'
rs:basetable='#t1' rs:basecolumn='DDDComment'>
<s:datatype dt:type='string' rs:dbtype='str' dt:maxLength='255'/>
</s:AttributeType>
<s:extends type='rs:rowbase'/>
</s:ElementType>
</s:Schema>
<rs:data>
<z:row ATCCode='A01AA01' DDD='1.1' UnitType='mg' AdmCode='O' DDDComment='0.5 mg Fluoride'/>
<z:row ATCCode='A01AA03' DDD='1.1' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB02' DDD='60' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB03' DDD='30' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB04' DDD='40' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB05' DDD='0.18' UnitType='g' AdmCode='O'/>
<z:row ATCCode='A01AB06' DDD='3' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB07' DDD='80' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB09' DDD='0.2' UnitType='g' AdmCode='O'/>
<z:row ATCCode='A01AB10' DDD='20' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A01AB23' DDD='1' UnitType='mg' AdmCode='O'/>
<z:row ATCCode='A02AA04' DDD='3' UnitType='g' AdmCode='O'/>
<z:row ATCCode='A02AB02' DDD='5' UnitType='g' AdmCode='O'/>
</rs:data>
</xml>
Java模型类:-
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "xml")
public class Xml{
@XmlElement
private List<Data> data;
}
然后加载它
private Xml unmarshall() throws JAXBException, IOException {
JAXBContext jc = JAXBContext.newInstance(Xml.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
return (Xml) unmarshaller.unmarshal(new BufferedReader(new FileReader(new File(fileName)));
}
但我总是将数据字段设为空。所以我的问题是这种类型的 xml 的正确模型是什么?