【发布时间】:2016-02-10 22:16:42
【问题描述】:
在我的应用程序中,我有一个将 XML 标记动态发送到适当通道的路由器:
<!-- Route each tag to the appropiate channel -->
<int-xml:xpath-router id="router" input-channel="routerChannel" evaluate-as-string="true">
<int-xml:xpath-expression expression="concat(name(./node()), 'Channel')" />
</int-xml:xpath-router>
使用此 XML 将每个标签路由到 serviceChannel 和 activityChannel
<root>
<service attr1="x" attr2="y" />
<activity anotherAttr="W" />
</root>
我的服务激活器 POJO 是这样的:
class Service {
private String attr1;
private String attr2;
/* Setter and getter omitted */
}
这是 applicationContext.xml 配置:
<!-- Service activators -->
<int:service-activator input-channel="serviceChannel" method="schedule">
<bean class="it.mypkg.Service" />
</int:service-activator>
路由器将整个Node 发送到bean,我需要“手动”提取属性。
有一种方法可以“解组”Node,所以在 attr1 和 attr2 中,我将获得 XML 中提供的值?
通常我使用一个简单的 Unmarshaller(使用 JAXB)并添加注释 @XmlRootElement、@XmlAttribute 等等。
我认为在传递给 POJO 之前,我需要使用 SI-XML UnmarshallingTransformer,但我真的不知道该怎么做......而且这应该是“足够通用”来处理所有标签(当然,所有 POJO 类,如 @ 987654334@ 和 Activity 将有 @XmlAttribute 等)
【问题讨论】: