fragment in Smooks
Transform the xml content into JavaBean, with Smooks. And the xml file looks like
<Article>
<AticleNo>PM20120424001</ AticleNo>
<ArticleTopic>2012 May 1st</ ArticleTopic >
<PostBy>201204290830</PostBy>
<ArticleContent>
<div align="center"><strong>Hello<br /></strong>
<div align="left">I want to post:<br />
<ol>
<li>1<span style="color:#FF0000;">5%</span>XX/li>
<li>2<span style="color:#FF0000;">9999</span>,XX<span style="color:#FF0000;">5%</span></li>
<li>3<span style="color:#FF0000;">99999</span>,XXY<span style="color:#FF0000;">10%</span></li>
</ol>
<p><br />
</p>
<p>Peter<br />
</p>
</div>
</div>
</ ArticleContent >
</Article >
And if we use
<jb:bean beanId="article" class="java.util.HashMap" createOnElement="Article">
<jb:value property="AticleNo" data="AticleNo" />
<jb:value property="ArticleTopic" data="ArticleTopic" />
<jb:value property="PostBy" data="PostBy"/>
<jb:value property="ArticleContent" data="ArticleContent"/>
</jb:bean>
We got an empty articeContent, because the articlecontent itself contains an xml stream.
<frag:serialize fragment="Article/ArticleContent" bindTo="contentbody" childContentOnly="true"/>
<jb:bean beanId="article" class="java.util.HashMap" createOnElement="Article">
<jb:value property="AticleNo" data="AticleNo" />
<jb:value property="ArticleTopic" data="ArticleTopic" />
<jb:value property="PostBy" data="PostBy"/>
</jb:bean>
The Java Code:
JavaResult jr = new JavaResult();
String message = (String) exchange.getIn().getBody();
smooks.filterSource(new StreamSource(new ByteArrayInputStream(message.getBytes())), jr);
Map<String, String> map= jr.getBean(HashMap.class);
String contentbody = jr.getBean("contentbody").toString();
The map is the binded bean from <jb:bean xxx and the contentbody is the fragmented articlecontent

