如何通过castor生成的对象在XML中按属性值查找元素
我无法通过 Castor 生成的类在 XML 文件中按属性值查找元素。
Castor 很好地完成了 XML 到实体类的映射。但是,它不提供按名称查找元素的方法(假设名称是元素的属性)。 API 只能通过元素列表中的索引来查找元素。目前看来,如果我想按名称查找元素,我必须循环遍历元素列表才能找到它。因为它解组的每个类都有不同的字段,所以似乎很难编写一个通用方法来按名称查找元素。有没有更好的方法通过名称从元素列表中查找元素?
I am having trouble looking up elements by attribute value in the XML file via castor generated classes.
Castor does the mapping of XML to entity classes very good. However it doesn't provide means to find the element by name (assume that name is an attribute of the element). The API can only find an element by its index in the element list. At the moment it seems if I want to find an element by name I have to loop through the element list to find it. Because every class it unmarshalled has different fields it seems hard to write a generic method to find an element by name. Is there a better way to find an element from the element list by name?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:我是 EclipseLink JAXB (MOXy) 负责人,以及 JAXB (JSR-222) 专家组成员。
不确定 Castor,但您可以使用 EclipseLink JAXB (MOXy) 轻松完成此操作。
客户
请注意如何通过
@XmlPath
注释在映射上指定条件[@name='address']
:XML< /strong>
了解更多信息
Note: I'm the EclipseLink JAXB (MOXy) lead, and a member of the JAXB (JSR-222) expert group.
Not sure about Castor, but you can do this easy enough with EclipseLink JAXB (MOXy).
Customer
Note how a condition
[@name='address']
is specified on the mapping via the@XmlPath
annotation:XML
For More Information