gpt4 book ai didi

java - 按属性名称与标记名称解码 XML 元素

转载 作者:行者123 更新时间:2023-11-30 11:13:58 25 4
gpt4 key购买 nike

这是我要解码的 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>

我在解码两个行集标记 copilots 和 items 时遇到问题(解码后对象为空)。另外,我无法控制架构。下面是表示 eveapi/result/rowset/row 级别标签的类。事件由 jaxb 实例化。 Pilot 解码良好。但是我无法让副驾驶和项目工作,它们都是空的。

@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

有关详细信息,请参阅我博客上的以下帖子:

关于java - 按属性名称与标记名称解码 XML 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26141586/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com