解组XML元素与标签名
问题描述:
这里是我试图来解读XML:解组XML元素与标签名
<eveapi version="2" zkbapi="1">
<result>
<rowset name="events">
<row eventID="41551776" solarSystemID="30003069">
<pilot characterID="1803362092"/>
<rowset name="copilots">
<row characterID="914916227"/>
<row characterID="877714973"/>
</rowset>
<rowset name="items">
<row typeID="31055"/>
<row typeID="2048"/>
</rowset>
</row>
</rowset>
</result>
</eveapi>
我在解组两名集标签副驾驶员和项目的问题(对象是解组后空)。另外,我无法控制架构。以下是表示eveapi/result/rowset/row级别标签的类。事件由jaxb实例化。飞行员很好。但我不能让copilots和项目工作,他们都是空的。
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "row")
public class Event {
@XmlElement(name = "pilot")
Pilot pilot;
@XmlPath("rowset[@name='copilots']")
Copilots copilots;
@XmlPath("rowset[@name='items']")
Items items;
是我在做什么?谢谢!
答
要使用@XmlPath
注释,您需要确保您使用的是EclipseLink JAXB (MOXy)作为JAXB提供程序。要做到这一点,你需要拥有的EclipseLink你的类路径和jaxb.properties
文件在同一个包您的域模型如下条目:
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
欲了解更多信息,请参见我的博客以下职位:
滑稽,我脱脂你的 “映射到元基于属性值”,彻底MISSE d需要jaxb.properties文件中的部分。这是深夜。一旦我添加它,一切都很好。非常感谢。和伟大的博客,顺便说一句。 – 2014-10-01 15:59:50