java by.xpath_如何通过XPath将XML映射到Java对象?(How to map an XML to Java objects by XPaths?)...

Given the XML example:

LOLOLOLOL

Which should be mapped to:

class MyFoo {

String lol;

String thisIsIt;

Object somethingUnrelated;

}

Constraints:

XML should not be transformed, it is provided as a parsed org.w3c.dom.Document object.

Class does not and will not map 1:1 to the XML.

I'm only interested to map specific paths of the XML to specific fields of the object.

My dream solution would look like:

@XmlMapped

class MyFoo {

@XmlElement("/fooRoot/bar/lol")

String lol;

@XmlElement("/noob/boon/thisIsIt")

String thisIsIt;

@XmlIgnore

Object somethingUnrelated;

}

Does anything likewise exists? What I've found either required a strict 1:1 mapping (e.g. JMX, JAXB) or manual iteration over all fields (e.g. SAX, Commons Digester.)

JiBX binding definitions come the nearest to what I'm lokking for. However, this tool is ment to marshall/unmarshall complete hierarchy of Java objects. I only would like to extract parts of an XML document into an existing Java bean at runtime.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值