我正在尝试使用 SimpleXML 解析包含以下元素的 XML 文档(来自Amazon Product Advertising APIItemLookupResponse
的一本书):
<ItemAttributes>
<Author>Shane Conder</Author>
<Author>Lauren Darcey</Author>
<Manufacturer>Pearson Educacion</Manufacturer>
<ProductGroup>Book</ProductGroup>
<Title>Android Wireless Application Development: Barnes & Noble Special Edition</Title>
</ItemAttributes>
我的问题是我不知道如何处理多个可能的Author
元素。
这是我现在拥有的相应 POJO(普通旧 Java 对象)的内容,请记住它不处理多个Author
s 的情况:
@Element
public class ItemAttributes {
@Element
public String Author;
@Element
public String Manufacturer;
@Element
public String Title;
}
(我不关心ProductGroup
,所以它不在课堂上——我只是将 SimpleXML 的strict
模式设置off
为允许这样做。)
我在与这种情况相对应的文档中找不到示例。使用ElementList
with(inline=true)
似乎是正确的,但我没有看到如何为 String 做它(与单独的 Author 类相反,我不需要也看不到它是如何工作的)。
这是一个类似的问题和答案,但对于 PHP:php - simpleXML 如何访问与其他元素同名的特定元素?我不知道 Java 等效于接受的答案。
提前致谢。