XML片段:
<datasource formatted-name="blah" inline="blah">
<repository-location derived-from="blah" id="blah" path="blah" revision="blah" site="blah"/>
</datasource>
我正在尝试将所有内容解组到一个类(DataSource)中,其中包含嵌套的静态类。以下是我的DataSource类:
@XmlRootElement(name = "datasource")
@XmlAccessorType(XmlAccessType.FIELD)
public class DataSource {
@XmlAttribute(name = "formatted-name")
protected String formattedName;
@XmlAttribute(name = "inline")
protected String inline;
@XmlElement(name = "repository-location")
protected RepositoryLocation repositoryLocation;
// public getters and setters for fields above
@XmlAccessorType(XmlAccessType.FIELD)
public static class RepositoryLocation {
@XmlAttribute(name = "derived-from")
protected String derivedFrom;
@XmlAttribute(name = "id")
protected String id;
@XmlAttribute(name = "path")
protected String path;
@XmlAttribute(name = "revision")
protected String revision;
@XmlAttribute(name = "site")
protected String site;
// public getters and setters for fields above
}
}
Unmarshaller:
JAXBContext jaxbContext = JAXBContext.newInstance(DataSource.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(responseXML);
dataSourceResponse = (DataSource) unmarshaller.unmarshal(reader);
我能成功输出数据源字段“formattedName”和“inline”,但“repositoryLocation”为空。有人可以帮忙吗?
repositoryLocation
的getter/setter吗? - ulab