<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>redstream &#187; XML/ XSD/ XSLT</title>
	<atom:link href="http://www.redstream.nl/category/technical/xml-xsd-xslt/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redstream.nl</link>
	<description>Pragmatic Integrators</description>
	<lastBuildDate>Fri, 27 Jan 2012 19:31:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Using Parameters in Your Mule Configuration Files</title>
		<link>http://www.redstream.nl/2012/01/27/using-parameters-in-your-mule-configuration-files/</link>
		<comments>http://www.redstream.nl/2012/01/27/using-parameters-in-your-mule-configuration-files/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 19:31:59 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Mule3]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2915</guid>
		<description><![CDATA[Although I am not always happy with the online documentation of the Mule ESB I found this article quite good. I have set up our configuration of Mule ESB implementation on several projects this way and it has proved to &#8230; <a href="http://www.redstream.nl/2012/01/27/using-parameters-in-your-mule-configuration-files/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2012%2F01%2F27%2Fusing-parameters-in-your-mule-configuration-files%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2012%2F01%2F27%2Fusing-parameters-in-your-mule-configuration-files%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Although I am not always happy with the online documentation of the <a href="http://www.mulesoft.org/">Mule ESB</a> I found <a href="http://www.mulesoft.org/documentation/display/MULE3USER/Using+Parameters+in+Your+Configuration+Files">this article</a> quite good. I have set up our configuration of Mule ESB implementation on several projects this way and it has proved to be working nicely. Although last time I got into the following issue. To use a datasource in my Mule3 project I had configured it like this in my Mule config file:</p>

<div class="wp_codebox"><table><tr id="p29153"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2915code3"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:oracle-data-source</span> </span>
<span style="color: #009900;">          <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span> </span>
<span style="color: #009900;">          <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;${db.username}&quot;</span> </span>
<span style="color: #009900;">          <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${db.password}&quot;</span> </span>
<span style="color: #009900;">          <span style="color: #000066;">host</span>=<span style="color: #ff0000;">&quot;${db.host}&quot;</span> </span>
<span style="color: #009900;">          <span style="color: #000066;">port</span>=<span style="color: #ff0000;">&quot;${db.port}&quot;</span> </span>
<span style="color: #009900;">          <span style="color: #000066;">sid</span>=<span style="color: #ff0000;">&quot;{db.sid}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>However, when I deployed the application on my Mule instance I got the following XML parse exception:</p>
<blockquote><p>
org.xml.sax.SAXParseException: cvc-datatype-valid.1.2.1: &#8216;${db.port}&#8217; is not a valid value for &#8216;integer&#8217;.
</p></blockquote>
<p>This is caused by the fact that the XML is validated against its XSD before the parameters are resolved. Although I found threads in several forums that described a solution for this issue I chose the following (pragmatic) solution. I decided to configure the datasource like this:</p>

<div class="wp_codebox"><table><tr id="p29154"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p2915code4"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:oracle-data-source</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;${db.username}&quot;</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;${db.password}&quot;</span> </span>
<span style="color: #009900;">         <span style="color: #000066;">url</span>=<span style="color: #ff0000;">&quot;jdbc:oracle:thin:@//${db.host}:${db.port}/${db.sid}&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></td></tr></table></div>

<p>This way the XML validates fine against its XSD and during runtime the parameters are resolved.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2012/01/27/using-parameters-in-your-mule-configuration-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XSLT 2.0 and Java Extensions</title>
		<link>http://www.redstream.nl/2011/03/29/xslt-2-0-and-java-extensions/</link>
		<comments>http://www.redstream.nl/2011/03/29/xslt-2-0-and-java-extensions/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 19:12:55 +0000</pubDate>
		<dc:creator>Pascal Prins</dc:creator>
				<category><![CDATA[MapForce]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2598</guid>
		<description><![CDATA[We use a fair lot of XSLT transformations in our projects. Since making XSLT stylesheets is a tedious and error-prone job, we use Altova MapForce to do the job. MapForce is very versatile, but can not always cope with the &#8230; <a href="http://www.redstream.nl/2011/03/29/xslt-2-0-and-java-extensions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F29%2Fxslt-2-0-and-java-extensions%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F29%2Fxslt-2-0-and-java-extensions%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>We use a fair lot of XSLT transformations in our projects. Since making XSLT stylesheets is a tedious and error-prone job, we use <a href="http://www.altova.com/mapforce.html" target="_blank">Altova MapForce</a> to do the job. MapForce is very versatile, but can not always cope with the requirements our customers come up with. This time, the customer asked us to implement some sort of maintainable translation mechanism. This mechanism should be able to translate incoming values using a user maintainable collection of values. This way, the transformation process does not need to be changed if a translation is added or updated.</p>
<p>Adding a (hardcoded) parameterized XSLT template is not an option, because this is not maintainable without changing the stylesheet. The answer? XSLT Java extensions!</p>
<p>In this blog I&#8217;ll show you a simple example on how to use Java extensions in a XSLT 2.0 stylesheet.</p>
<p><span id="more-2598"></span></p>
<p>We&#8217;ll start with a very simple &#8220;Hello World!&#8221;-isch example. I&#8217;ve created the following Java class which we will be using in our stylesheet:</p>
<h3>Our custom Java class</h3>

<div class="wp_codebox"><table><tr id="p25989"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code" id="p2598code9"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.utils</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Properties</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> XsltUtils <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Your default Hello World! method.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> greeting<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Hello, &quot;</span> <span style="color: #339933;">+</span> name <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; !&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Notice that the <code>greeting</code> method is <code>public static</code> (not really needed, but makes things easier) .</p>
<p>I packaged the project into a single jar (let&#8217;s assume it is called: <code>redstream-xslt-demo-1.0-SNAPSHOT.jar</code>) using <code>mvn clean package</code>.</p>
<h3>The XSL stylesheet</h3>
<p>Next up, creating our stylesheet ! (We will be dealing with the jar later) Use the following stylesheet:</p>

<div class="wp_codebox"><table><tr id="p259810"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code" id="p2598code10"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:fn</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/xpath-functions&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">xmlns:demo</span>=<span style="color: #ff0000;">&quot;java:nl.redstream.utils.XsltUtils&quot;</span> </span>
<span style="color: #009900;">    <span style="color: #000066;">exclude-result-prefixes</span>=<span style="color: #ff0000;">&quot;fn demo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;dataset&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:for-each</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;row/column&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;name&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@name&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
              <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;value&quot;</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;demo:greeting(fn:string(@value))&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/column<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:for-each<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Notice two things:<br />
- <strong>Line 5</strong> contains a declaration of our custom namespace. Just <code>java:</code> and the FQN of your custom Java class. The prerequisite is that the class (optionally packaged in a jar) is on the classpath.<br />
- <strong>Line 15</strong> contains a reference to our Java function. Notice that you can use an Xpath expression which will be resolved at runtime and passed as an argument to the <code>greeting</code> method.</p>
<h3>Disclaimer</h3>
<p>Remember the declaration of the namespace? This is dependent of the used XSLT engine. When using Saxon, you have to use the <code>java:FQN</code> declaration. When you are using Xalan, for example, you use <code>xalan://FQN</code>. Please check the documentation of your selected XSLT engine, before you declare the namespace.</p>
<h3>XMLSpy</h3>
<p>We could perform the XSL transformation using the command line, but we are using <a target="_blank" href="http://www.altova.com/xml-editor/">Altova XMLSpy</a> for this. By default, XMLSpy uses a built-in XSLT engine, but this can be changed to a custom one. Goto: &#8220;Tools -> Options: External XSL transformation program&#8221; and copy-paste the following: <code>java -cp C:\develop\redstream-xslt-demo-1.0-SNAPSHOT.jar;C:\develop\saxon8.jar net.sf.saxon.Transform -o %2 %1 %3</code>.</p>
<p>We will be using <a target="_blank" href="http://saxon.sourceforge.net/">Saxon</a> as XSLT engine, because the endresult will be packaged in a Mule ESB application &#8230; and Mule uses Saxon (so, that&#8217;s why). Should you want to use another XSLT engine, customize the &#8216;External XSL transformation program&#8217; in XMLSpy accordingly. Notice that all necessary jar&#8217;s are copied to the <code>c:\develop</code> directory and included in the classpath (including our custom jar).</p>
<p>Assign the following XML to the XSL using <code>XSL/XQuery -> Assign sample XML file</code>:</p>

<div class="wp_codebox"><table><tr id="p259811"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2598code11"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;greeting&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;foo&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;another&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;bar&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>After pressing F10 the following output should be the result of the transformation:</p>

<div class="wp_codebox"><table><tr id="p259812"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2598code12"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;greeting&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Hello, foo !&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;column</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;another&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Hello, bar !&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/row<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>What&#8217;s happened is that values <code>foo</code> and <code>bar</code> were passed to the Java <code>greeting</code> method and returned the displayed string. Of course this is a simplified example, but you&#8217;ll catch the drift. This opens up possibilites: you now can breakout of the XSLT 2.0 barriers and use Java where needed. Use your imagination to create your own custom Java class.</p>
<p>That&#8217;s it &#8230; we&#8217;ve shown that you can use custom Java classes in your XSLT 2.0 transformation. In my next post, I&#8217;ll show you how to extend Altova MapForce and make this reusable (read: drag-and-drop the Java methods graphically to auto generate the XSLT 2.0 stylesheet).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/03/29/xslt-2-0-and-java-extensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing DiffGram element in web service messages</title>
		<link>http://www.redstream.nl/2011/03/27/removing-diffgram-element-in-web-service-messages/</link>
		<comments>http://www.redstream.nl/2011/03/27/removing-diffgram-element-in-web-service-messages/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 19:37:34 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[JAXB]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2584</guid>
		<description><![CDATA[Some time ago I was asked to review existing web services for a customer. The main thing I noticed was that they were using Microsoft&#8217;s diffgram elements and attributes in their input and output messages. I was not familiar with &#8230; <a href="http://www.redstream.nl/2011/03/27/removing-diffgram-element-in-web-service-messages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F27%2Fremoving-diffgram-element-in-web-service-messages%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F27%2Fremoving-diffgram-element-in-web-service-messages%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Some time ago I was asked to review existing web services for a customer. The main thing I noticed was that they were using Microsoft&#8217;s <a href="http://msdn.microsoft.com/en-us/library/ms172088.aspx">diffgram</a> elements and attributes in their input and output messages. I was not familiar with this format but found out that it has been created by Microsoft to make synchronizing datasets in .Net easier. In this case the web services were implemented with <a href="http://static.springsource.org/spring-ws/site/">Spring-WS</a>, so there was no real reason to use this format on the server side. Besides, it only makes the web service less useful on the client side since it leads to complications if you want to use a XML-Object mapper like JAXB (see <a href="http://www.coderanch.com/t/427321/Web-Services/java/Unmarshall-JAXB-Error">this</a> for example). One of the issues with Diffgram is that, besides the XML containing the Diffgram element, also the XSD is included. This XSD describes the content of the Diffram Dataset, however, the XSD and the resulting Dataset do not match because extra attributes are added (this is described in more detail <a href="http://publib.boulder.ibm.com/infocenter/dmndhelp/v6r1mx/index.jsp?topic=/com.ibm.wbit.610.help.sib.mediation.ui.doc/topics/tdiffgram.html">here</a>).<span id="more-2584"></span><br />
I decided to create a new web service that would accept incoming messages without this diffgram and ms-data elements and attributes (and would have a similar response). To make this work, I made use of an XSL transformation in combination with the interceptors in Spring-WS (the assumption is that only the content of the DataInstance part of the DiffGram are interesting).<br />
For example this is the original request the web service is expecting:</p>

<div class="wp_codebox"><table><tr id="p258417"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p2584code17"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;diffgr:diffgram</span> <span style="color: #000066;">xmlns:msdata</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-msdata&quot;</span> <span style="color: #000066;">xmlns:diffgr</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-diffgram-v1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerDataSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers</span> <span style="color: #000066;">diffgr:id</span>=<span style="color: #ff0000;">&quot;Customers1&quot;</span> <span style="color: #000066;">msdata:rowOrder</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">diffgr:hasChanges</span>=<span style="color: #ff0000;">&quot;inserted&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ALFKI<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>New Company<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers</span> <span style="color: #000066;">diffgr:id</span>=<span style="color: #ff0000;">&quot;Customers2&quot;</span> <span style="color: #000066;">msdata:rowOrder</span>=<span style="color: #ff0000;">&quot;1&quot;</span>  <span style="color: #000066;">diffgr:hasChanges</span>=<span style="color: #ff0000;">&quot;inserted&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ANATR<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Ana Trujillo Emparedados y Helados<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers</span> <span style="color: #000066;">diffgr:id</span>=<span style="color: #ff0000;">&quot;Customers3&quot;</span> <span style="color: #000066;">msdata:rowOrder</span>=<span style="color: #ff0000;">&quot;2&quot;</span>  <span style="color: #000066;">diffgr:hasChanges</span>=<span style="color: #ff0000;">&quot;inserted&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ANTON<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Antonio Moreno Taquera<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers</span> <span style="color: #000066;">diffgr:id</span>=<span style="color: #ff0000;">&quot;Customers4&quot;</span> <span style="color: #000066;">msdata:rowOrder</span>=<span style="color: #ff0000;">&quot;3&quot;</span>  <span style="color: #000066;">diffgr:hasChanges</span>=<span style="color: #ff0000;">&quot;inserted&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AROUT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Around the Horn<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerDataSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/diffgr:diffgram<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>I created a new web service endpoint to which I added the XSLT interceptors. The new endpoint would expect this as a request:</p>

<div class="wp_codebox"><table><tr id="p258418"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p2584code18"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerDataSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ALFKI<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>New Company<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ANATR<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Ana Trujillo Emparedados y Helados<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ANTON<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Antonio Moreno Taquera<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AROUT<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Around the Horn<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CompanyName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CustomerDataSet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As you can see this last example is quite simple and easy to use in combination with JAXB for example.<br />
To create the original request out of the new one I made use of the following XSLT:</p>

<div class="wp_codebox"><table><tr id="p258419"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code" id="p2584code19"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">xmlns:fo</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Format&quot;</span> <span style="color: #000066;">xmlns:xs</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span> <span style="color: #000066;">xmlns:fn</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/xpath-functions&quot;</span> <span style="color: #000066;">exclude-result-prefixes</span>=<span style="color: #ff0000;">&quot;xs fn fo&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;diffgr:diffgram</span> <span style="color: #000066;">xmlns:msdata</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-msdata&quot;</span> <span style="color: #000066;">xmlns:diffgr</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-diffgram-v1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
				<span style="color: #808080; font-style: italic;">&lt;!-- copy the attributes (if any) of the root element --&gt;</span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
				<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/diffgr:diffgram<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- match any other element and copy it with the attributes --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/CustomerDataSet/Customers&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;id&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-diffgram-v1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Customers<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;position()&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;rowOrder&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-msdata&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;position()-1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;hasChanges&quot;</span> <span style="color: #000066;">namespace</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-diffgram-v1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>inserted<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>And for the response the opposite transformation is performed. The original response is used as input and the XSLT will filter out all diffgram and ms-data elements and attributes.<br />
Here is an example XSL that takes the original CustomerDataSet as input and tranforms it the the more &#8216;simple&#8217; format:</p>

<div class="wp_codebox"><table><tr id="p258420"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p2584code20"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?altova_samplexml</span> example-original.xml<span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;2.0&quot;</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&quot;</span> <span style="color: #000066;">xmlns:diffgr</span>=<span style="color: #ff0000;">&quot;urn:schemas-microsoft-com:xml-diffgram-v1&quot;</span> <span style="color: #000066;">xmlns:fo</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Format&quot;</span> <span style="color: #000066;">xmlns:xs</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span> <span style="color: #000066;">xmlns:fn</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/xpath-functions&quot;</span> <span style="color: #000066;">exclude-result-prefixes</span>=<span style="color: #ff0000;">&quot;xs fn fo &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #808080; font-style: italic;">&lt;!-- copy the attributes (if any) of the root element --&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- match any other element and copy it with the attributes. Use local-name to get rid of the diffgr and ms-data namespaces --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{local-name()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- do not copy the attributes for  element'Customers' &quot;/&gt; --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/diffgr:diffgram/CustomerDataSet/Customers&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{local-name()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #808080; font-style: italic;">&lt;!-- Remove the tag for the diffgram --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/diffgr:diffgram&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>With this post I have shown how you can use a simple XSLT to get rid of the Diffgram elements and attributes, of course with some assumptions that should be taken into account.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/03/27/removing-diffgram-element-in-web-service-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using parameters with XSLT in Mule</title>
		<link>http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/</link>
		<comments>http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 11:31:18 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MapForce]]></category>
		<category><![CDATA[Mule2]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://www.redstream.nl/?p=2564</guid>
		<description><![CDATA[Recently I got into a situation where I had to put &#8216;metadata&#8217; values (which were part of the Mule Message) into the XML result of an XSLT transformer. Let me explain the situation with an example. Imagine you have an &#8230; <a href="http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F04%2Fusing-parameters-with-xslt-in-mule%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2011%2F03%2F04%2Fusing-parameters-with-xslt-in-mule%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Recently I got into a situation where I had to put &#8216;metadata&#8217; values (which were part of the Mule Message) into the XML result of an XSLT transformer. Let me explain the situation with an example. Imagine you have an &#8216;order&#8217; xml that needs to be translated into an &#8216;invoice&#8217; xml. Here is a simple &#8216;order.xsd&#8217;:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/order-xsd.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/order-xsd.png" alt="" title="order-xsd" width="355" height="126" class="aligncenter size-full wp-image-2568" /></a></p>
<p>Here is the &#8216;invoice.xsd&#8217;:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/invoice-xsd.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/invoice-xsd-300x106.png" alt="" title="invoice-xsd" class="aligncenter size-medium wp-image-2569" /></a></p>
<p>The mapping for the transformation looks like this in MapForce:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-without-param.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-without-param-300x133.png" alt="" title="mapping-without-param" class="aligncenter size-medium wp-image-2570" /></a><span id="more-2564"></span></p>
<p>Now the invoice number that is used in the invoice should be the MuleMessage correlationID&#8230;. (I know, weird situation, but it is only an example). The first thing that came to mind was to create a new transformer that would run after the XSLT transformer. This new transformer would add the element &#8216;invoicenr&#8217;  with the correlationID as value to the payload of the MuleMessage. But it can be done much easier! Here is the modified mapping that I created with MapForce:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-with-param.png"><img src="http://www.redstream.nl/wp-content/uploads/2011/03/mapping-with-param-300x288.png" alt="" title="mapping-with-param" class="aligncenter size-medium wp-image-2571" /></a><br />
In MapForce you can add extra input parameters for the XSL mapping as shown above. Now generate the XSLT and use that as basis for your Mule XSLT Transformer. In the Mule config you add the context-property to your XSL Transformer configuration to tell Mule with which value the parameter in the XSLT file should be filled:</p>

<div class="wp_codebox"><table><tr id="p256422"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p2564code22"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mule</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/core/2.2&quot;</span></span>
<span style="color: #009900;">     <span style="color: #000066;">xmlns:xm</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/xml/2.2&quot;</span></span>
<span style="color: #009900;">     ...</span>
<span style="color: #009900;">     <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/xml/2.2 http://www.mulesource.org/schema/mule/xml/2.2/mule-xml.xsd</span>
<span style="color: #009900;">     ...</span>
<span style="color: #009900;">     &quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:xslt-transformer</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;orderToInvoiceTransformer&quot;</span> <span style="color: #000066;">xsl-file</span>=<span style="color: #ff0000;">&quot;xsl/order-to-invoice.xsl&quot;</span> <span style="color: #000066;">outputEncoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:context-property</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;invoiceNr&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;#[message:correlationId]&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ship:xslt-transformer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    ...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>This makes it a very clean and powerful way to add metadata to your payload might you ever need this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2011/03/04/using-parameters-with-xslt-in-mule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reloadable XSLT Transformer in Mule</title>
		<link>http://www.redstream.nl/2010/12/19/reloadable-xslt-transformer-in-mule/</link>
		<comments>http://www.redstream.nl/2010/12/19/reloadable-xslt-transformer-in-mule/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 19:10:00 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Mule2]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[MapForce]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=2032</guid>
		<description><![CDATA[One of the main functions of a Mule ESB application (besides transporting messages) is transforming messages to another format. Nowadays a lot of messages are XML based so a lot of transformations are done by using XSLT, or in Mule &#8230; <a href="http://www.redstream.nl/2010/12/19/reloadable-xslt-transformer-in-mule/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F12%2F19%2Freloadable-xslt-transformer-in-mule%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F12%2F19%2Freloadable-xslt-transformer-in-mule%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>One of the main functions of a <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Home">Mule ESB</a> application (besides transporting messages) is transforming messages to another format. Nowadays a lot of messages are XML based so a lot of transformations are done by using <a href="http://en.wikipedia.org/wiki/XSLT">XSLT</a>, or in Mule terminology, an <a href="http://www.mulesoft.org/documentation/display/MULE2USER/XSLT+Transformer">XSLT Transformer</a>. In our current project this is no different.</p>
<p>As I posted <a href="http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/">before</a> we happily using <a href="http://www.altova.com/mapforce.html">Altova Mapforce</a> for this. But this also means that a lot of changes and issues during the development are being solved by modifying the XSLT. In our Mule ESB setup we have deployed our Mule applications as a WAR in Tomcat. So this means to take our modified XSLT into account we have to redeploy the WAR or at least, stop and start the WAR in Tomcat. And as we found out, if the Mule application is inside a JAR inside the WAR we had to stop and start the complete Tomcat instance for our changes to be picked up.</p>
<p>To solve this issue we have created our own instance of the Xslt Transformer in Mule. Our implementation checks for the timestamp of the XSLT file and reloads it if there is found a newer XSLT file. This way we don&#8217;t have to restart our Tomcat if a newer version is in place. In a production environment you might want to discard this functionality to avoid unexpected behaviour of the running applications but I leave that up to you. In this post I will show you how our implementation of the XSLT Transformer works. <span id="more-2032"></span><br />
The example I use in this pots is the same as I had in the previous post. I have an XSD that describes an Order and I transform it with a XSL file to an Invoice. The schema for the Order looks like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/11/rs-schema.png"><img class="alignnone size-medium wp-image-1994" title="rs-schema" src="http://www.redstream.nl/wp-content/uploads/2010/11/rs-schema-300x135.png" alt="" width="300" height="135" /></a></p>
<p>The schema for the Invoice looks like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/11/invoice.png"><img class="alignnone size-medium wp-image-2034" title="invoice" src="http://www.redstream.nl/wp-content/uploads/2010/11/invoice-300x133.png" alt="" width="300" height="133" /></a></p>
<p>The mapping in MapForce looks like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/11/mapping.png"><img class="alignnone size-medium wp-image-2033" title="mapping" src="http://www.redstream.nl/wp-content/uploads/2010/11/mapping-300x159.png" alt="" width="300" height="159" /></a></p>
<p>Now for the real thing. <a href="http://www.redstream.nl/wp-content/uploads/2010/11/XsltTransformer.java">Here</a> you can find the complete code  of our version of the XSL Transformer. Next I show just the important parts that we have changed</p>

<div class="wp_codebox"><table><tr id="p203224"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
</pre></td><td class="code" id="p2032code24"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.transformer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> …
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
* This class is mainly a copy of the XsltTransformer supplied by Mule.
* Checks are added for the XSLT file timestamp, so if the XSLT file is changed
* , the pool will be reloaded, so the new version of the XSLT is used.
*
* @author Redstream
*/</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> XsltTransformer <span style="color: #000000; font-weight: bold;">extends</span> AbstractXmlTransformer <span style="color: #000000; font-weight: bold;">implements</span> MuleContextAware
<span style="color: #009900;">&#123;</span>
...
  <span style="color: #666666; font-style: italic;">/* added by Redstream */</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">long</span> lastModified<span style="color: #339933;">;</span>
&nbsp;
...
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> initialise<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> InitialisationException
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">try</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// Set XSLT timestamp</span>
      java.<span style="color: #006633;">net</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a> url <span style="color: #339933;">=</span> IOUtils.<span style="color: #006633;">getResourceAsUrl</span><span style="color: #009900;">&#40;</span>xslFile, getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">try</span>
      <span style="color: #009900;">&#123;</span>
        file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">toURI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>file <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastModified</span> <span style="color: #339933;">=</span> file.<span style="color: #006633;">lastModified</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      transformerPool.<span style="color: #006633;">addObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> te<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> InitialisationException<span style="color: #009900;">&#40;</span>te, <span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
...
  <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doTransform<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> encoding, Source sourceDoc, Result result<span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a>
  <span style="color: #009900;">&#123;</span>
    DefaultErrorListener errorListener <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultErrorListener<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    javax.<span style="color: #006633;">xml</span>.<span style="color: #006633;">transform</span>.<span style="color: #006633;">Transformer</span> transformer <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Check XSLT timestamp and reload</span>
    java.<span style="color: #006633;">net</span>.<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aurl+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">URL</span></a> url <span style="color: #339933;">=</span> IOUtils.<span style="color: #006633;">getResourceAsUrl</span><span style="color: #009900;">&#40;</span>xslFile, getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a> file <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span>
    <span style="color: #009900;">&#123;</span>
      file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">toURI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      file <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afile+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">File</span></a><span style="color: #009900;">&#40;</span>url.<span style="color: #006633;">getPath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>file <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> file.<span style="color: #006633;">lastModified</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastModified</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>logger.<span style="color: #006633;">isDebugEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
        logger.<span style="color: #006633;">debug</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Reloading &quot;</span> <span style="color: #339933;">+</span> file.<span style="color: #006633;">getAbsolutePath</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">transformerPool</span>.<span style="color: #006633;">clear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">transformerPool</span>.<span style="color: #006633;">addObject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">lastModified</span> <span style="color: #339933;">=</span> file.<span style="color: #006633;">lastModified</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    ...
  <span style="color: #009900;">&#125;</span>
...
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/12/19/reloadable-xslt-transformer-in-mule/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>About Mule, content-based routing and namespaces</title>
		<link>http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/</link>
		<comments>http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 11:49:12 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Mule2]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1955</guid>
		<description><![CDATA[Some of our Mule ESB applications make use of content-based routing when processing a message. To implement this in Mule we use a filtering-router with a jaxen-filter. The most simple example looks like this: 1 2 3 4 5 6 &#8230; <a href="http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F08%2F21%2Fabout-mule-content-based-routing-and-namespaces%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F08%2F21%2Fabout-mule-content-based-routing-and-namespaces%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Some of our <a href="http://www.mulesoft.org/">Mule ESB</a> applications make use of <a href="http://www.eaipatterns.com/ContentBasedRouter.html">content-based routing</a> when processing a message. To implement this in Mule we use a <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Outbound+Routers#OutboundRouters-FilteringRouter">filtering-router</a> with a jaxen-filter. The most simple example looks like this:</p>

<div class="wp_codebox"><table><tr id="p195528"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1955code28"><pre class="xml" style="font-family:monospace;">...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;out-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:jaxen-filter</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;//firstname&quot;</span> <span style="color: #000066;">expectedValue</span>=<span style="color: #ff0000;">&quot;Pascal&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></td></tr></table></div>

<p>You can also use a XPath function in your jaxen-filter like this (if you want to check a certain element is in an XML message regardless the value of the element):</p>

<div class="wp_codebox"><table><tr id="p195529"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1955code29"><pre class="xml" style="font-family:monospace;">...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;out-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:jaxen-filter</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;local-name(//Relations)&quot;</span> <span style="color: #000066;">expectedValue</span>=<span style="color: #ff0000;">&quot;Relations&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></td></tr></table></div>

<p><span id="more-1955"></span><br />
The problem starts if you have to declare namespaces in your XPath expression. You can use namespaces in your XPath expression by declaring a <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Expressions+Configuration+Reference#ExpressionsConfigurationReference-NamespacesforXPathExpressions">namespace-manager</a> in your mule-config, like this:</p>

<div class="wp_codebox"><table><tr id="p195530"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p1955code30"><pre class="xml" style="font-family:monospace;">...
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace-manager</span> <span style="color: #000066;">includeConfigNamespaces</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;ns1&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://www.redstream.nl/relations/v1_1&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xm:namespace-manager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:outbound-endpoint</span> <span style="color: #000066;">ref</span>=<span style="color: #ff0000;">&quot;out-queue&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
       <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:jaxen-filter</span> <span style="color: #000066;">pattern</span>=<span style="color: #ff0000;">&quot;local-name(//ns1:Relations)&quot;</span> <span style="color: #000066;">expectedValue</span>=<span style="color: #ff0000;">&quot;Relations&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
     <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filtering-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre></td></tr></table></div>

<p>But if you run this example you will get the following exception:</p>
<blockquote><p>org.jaxen.UnresolvableException: No Such Function {http://www.mulesource.org/schema/mule/core/2.2}:local-name<br />
        at org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:127)<br />
        at org.jaxen.ContextSupport.getFunction(ContextSupport.java:242)<br />
        at org.jaxen.Context.getFunction(Context.java:216)<br />
        at org.jaxen.expr.DefaultFunctionCallExpr.evaluate(DefaultFunctionCallExpr.java:172)<br />
        at org.jaxen.expr.DefaultXPathExpr.asList(DefaultXPathExpr.java:102)<br />
        at org.jaxen.BaseXPath.selectNodesForContext(BaseXPath.java:674)<br />
        at org.jaxen.BaseXPath.selectSingleNodeForContext(BaseXPath.java:698)<br />
        at org.jaxen.BaseXPath.stringValueOf(BaseXPath.java:279)<br />
        at org.jaxen.BaseXPath.valueOf(BaseXPath.java:254)<br />
        at org.mule.module.xml.filters.JaxenFilter.accept(JaxenFilter.java:184)<br />
        at org.mule.module.xml.filters.JaxenFilter.accept(JaxenFilter.java:118)<br />
        at org.mule.routing.outbound.FilteringOutboundRouter.isMatch(FilteringOutboundRouter.java:119)<br />
        at org.mule.routing.outbound.DefaultOutboundRouterCollection. route(DefaultOutboundRouterCollection.java:72)<br />
        at org.mule.service.AbstractService.dispatchToOutboundRouter(AbstractService.java:867)<br />
        at org.mule.model.seda.SedaService.dispatchToOutboundRouter(SedaService.java:561)<br />
        at org.mule.model.seda.SedaService$ComponentStageWorker.doRun(SedaService.java:583)<br />
        at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:41)<br />
        at org.mule.work.WorkerContext.run(WorkerContext.java:310)<br />
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor. runWorker(ThreadPoolExecutor.java:1061)<br />
        at edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker. run(ThreadPoolExecutor.java:575)<br />
        at java.lang.Thread.run(Thread.java:637)
</p></blockquote>
<p>Although it is logged as warning it makes the filter to return no matching values and the XML message is discarded (although I use the jaxen-filter here this also goes for the <a href="http://www.mulesoft.org/documentation/display/MULE2USER/XML+Module#XMLModule-Filters">jxpath-filter and the xpath-filter</a>).</p>
<p>The solution for this is quite simple: just give the XPath function a unique prefix (one that is not mapped to a namespace). So if you modify the last example and make the jaxen-filter like:<br />
<code>&lt;xm:jaxen-filter pattern="fn:local-name(//ns1:Relations)"  expectedValue="Relations"/&gt;</code><br />
or<br />
<code>&lt;xm:jaxen-filter pattern="abc:local-name(//ns1:Relations)" expectedValue="Relations"/&gt;</code><br />
it will work.<br />
You just have to make sure the prefix you use isn&#8217;t used in the declared <em>namespace-manager</em> because then the function is looked up (and not found) in the supplied XML document.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/08/21/about-mule-content-based-routing-and-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto Quickly Insert XML into a Database using Mule ESB</title>
		<link>http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/</link>
		<comments>http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/#comments</comments>
		<pubDate>Sat, 12 Jun 2010 09:04:47 +0000</pubDate>
		<dc:creator>Pascal Prins</dc:creator>
				<category><![CDATA[Mule]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1880</guid>
		<description><![CDATA[Mule ESB is a versatile service bus that contains numerous usable components out-of-the-box. In this blog I&#8217;ll show you how to process an incoming XML document, break it up into multiple parts and insert them into the database without using &#8230; <a href="http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F12%2Fhowto-quickly-insert-xml-into-a-database-using-mule-esb%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F12%2Fhowto-quickly-insert-xml-into-a-database-using-mule-esb%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Mule ESB is a versatile service bus that contains numerous usable components out-of-the-box. In this blog I&#8217;ll show you how to process an incoming XML document, break it up into multiple parts and insert them into the database without using any custom Java classes.</p>
<p><span id="more-1880"></span></p>
<p>In this example we will be using this (simple) XML document as source input. The document contains a collection of Customers.</p>

<div class="wp_codebox"><table><tr id="p188036"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p1880code36"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Steve<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Jobs<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1 Infinite Loop<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cupertino<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Bill<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/firstName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Gates<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1 Microsoft Way<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/street<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Washington<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>USA<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/country<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/address<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/customers<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>After breaking the XML up into multiple <code>Customer</code> entities, we will insert them into the following database structure:</p>

<div class="wp_codebox"><table><tr id="p188037"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1880code37"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">create</span> <span style="color: #993333; font-weight: bold;">table</span> CUSTOMERS <span style="color: #66cc66;">&#40;</span>
   first_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  last_name VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">64</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  street VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  city VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">128</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">,</span>  country VARCHAR2<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div>

<p>To split the XML document into multiple <code>Customer</code> entities, we&#8217;ll use an outbound splitting router like this one:</p>

<div class="wp_codebox"><table><tr id="p188038"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1880code38"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expression-splitter-router</span> <span style="color: #000066;">evaluator</span>=<span style="color: #ff0000;">&quot;xpath&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;//Customer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;stdio:outbound-enpdoint</span> <span style="color: #000066;">system</span>=<span style="color: #ff0000;">&quot;OUT&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expression-splitter-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The <code>xpath</code> evaluator mentioned in the <code>expression-splitter-router</code> excepts both Dom and String objects. This means we can just use plain XML files (no need to create a <code>w3c.dom.Document</code> first. It&#8217;ll be parsed on-the-fly.</p>
<p>Once the message has been split, we want each Customer to be inserted into a database. The trick here is to use the<a href="http://www.mulesoft.org/documentation/display/MULE2USER/JDBC+Transport"> JDBC transport</a>. We&#8217;ll need to configure a <code>connector</code> in which<br />
&#8220;named queries&#8221; can be configured. A &#8220;named query&#8221; is a PODS (~Plain Old Dml Statement) identified by a key.</p>

<div class="wp_codebox"><table><tr id="p188039"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1880code39"><pre class="xml" style="font-family:monospace;">    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbcConnector&quot;</span> <span style="color: #000066;">dataSource-ref</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:query</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;insertIntoFoobar&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;insert into FOOBAR (id, code, description) VALUES (#[map-payload:ID], #[map-payload:CODE], #[map-payload:DESCRIPTION])&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jdbc:connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>In this example, a Map payload is expected from which the values are derived. When using XML, an XPATH expression evaluator seems more appropriate (see final solution).</p>
<p>PS: It might be nice to know that <a target="_blank" href="http://www.mulesoft.org/documentation/display/MULE2USER/JDBC+Transport#JDBCTransport-UnnamedQueries">unnamed queries</a> are also supported.</p>
<p>I&#8217;ve introduced the basics, now let&#8217;s have a look at the complete Mule configuration:</p>

<div class="wp_codebox"><table><tr id="p188040"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
</pre></td><td class="code" id="p1880code40"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mule</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/core/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:spring</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/beans&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:vm</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/vm/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:xm</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/xml/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:jdbc</span>=<span style="color: #ff0000;">&quot;http://www.mulesource.org/schema/mule/jdbc/2.2&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:xsi</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xmlns:context</span>=<span style="color: #ff0000;">&quot;http://www.springframework.org/schema/context&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">xsi:schemaLocation</span>=<span style="color: #ff0000;">&quot;</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd</span>
<span style="color: #009900;">      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/xml/2.2 http://www.mulesource.org/schema/mule/xml/2.2/mule-xml.xsd</span>
<span style="color: #009900;">      http://www.mulesource.org/schema/mule/jdbc/2.2 http://www.mulesource.org/schema/mule/jdbc/2.2/mule-jdbc.xsd</span>
<span style="color: #009900;">      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;context:property-placeholder</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">&quot;classpath:my.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;org.enhydra.jdbc.standard.StandardDataSource&quot;</span> <span style="color: #000066;">destroy-method</span>=<span style="color: #ff0000;">&quot;shutdown&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;driverName&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.driverName}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;spring:property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;${db.url}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/spring:bean<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:connector</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;jdbcConnector&quot;</span> <span style="color: #000066;">dataSource-ref</span>=<span style="color: #ff0000;">&quot;jdbcDataSource&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:query</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">&quot;insertCustomer&quot;</span></span>
<span style="color: #009900;">                    <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;insert into CUSTOMERS (first_name, last_name, street, city, country) VALUES (#[xpath://Customer/FirstName],#[xpath://Customer/LastName],#[xpath://Customer/Address/Street],#[xpath://Customer/Address/City],#[xpath://Customer/Address/Country])&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jdbc:connector<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace-manager</span> <span style="color: #000066;">includeConfigNamespaces</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xm:namespace</span> <span style="color: #000066;">prefix</span>=<span style="color: #ff0000;">&quot;cus&quot;</span> <span style="color: #000066;">uri</span>=<span style="color: #ff0000;">&quot;http://www.redstream.nl/schema/customer/1.0&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xm:namespace-manager<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;processCustomers&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;vm:inbound-endpoint</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;processCustomersService&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/inbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;expression-splitter-router</span> <span style="color: #000066;">evaluator</span>=<span style="color: #ff0000;">&quot;xpath&quot;</span> <span style="color: #000066;">expression</span>=<span style="color: #ff0000;">&quot;//Customer&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jdbc:outbound-endpoint</span> <span style="color: #000066;">queryKey</span>=<span style="color: #ff0000;">&quot;insertCustomer&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/expression-splitter-router<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/outbound<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Et voila &#8230; using the above configuration, you will be able to process incoming XML and insert the contents in a database.</p>
<p>Some final notes:</p>
<ul>
<li>Use a <code>property-placeholder</code> to configure the database credentials.</li>
<li>When incoming XML contains namespaces, they could globally be configured using a <code>namespace-manager</code></li>
<li>Notice that the <code>jdbc:outbound-endpoint</code> refers to the named query by key</li>
<li>The named query will be &#8220;injected&#8221; with a single Customer entity, accessible by the XPATH expression evaluator</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/06/12/howto-quickly-insert-xml-into-a-database-using-mule-esb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing Altova Mapforce</title>
		<link>http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/</link>
		<comments>http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/#comments</comments>
		<pubDate>Fri, 21 May 2010 09:37:44 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MapForce]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[Altova]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1767</guid>
		<description><![CDATA[Although we see many advantages in using (free) open source tools or frameworks we keep our eyes open to check whether the chosen open source solution is best for our customer. We recently had a situation where we preferred a &#8230; <a href="http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F05%2F21%2Fintroducing-altova-mapforce%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F05%2F21%2Fintroducing-altova-mapforce%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Although we see many advantages in using (free) open source tools or frameworks we keep our eyes open to check whether the chosen open source solution is best for our customer.</p>
<p>We recently had a situation where we preferred a commercial solution over an open source one.<br />
For a specific interface, we had to map a <a href="http://en.wikipedia.org/wiki/Comma-separated_values">CSV file</a> to an <a href="http://en.wikipedia.org/wiki/XML">XML</a> file and this transformation should be processed by the Mule ESB. At first we looked at <a href="http://www.smooks.org/mediawiki/index.php?title=Main_Page">Smooks</a> to tackle this issue, as I described <a href="http://www.redstream.nl/2010/04/29/using-smooksmule-to-transform-csv-file-to-xml-one/">here</a>. It resulted in a workable solution, but as you can read in post, the transformation had to take place in two steps: first from CSV to simple XML format and secondly, a transformation from the simple XML to a more advanced XML schema. For this second transformation we made use of an <a href="http://www.w3schools.com/xsl/">XSL</a> stylesheet. We created the XSL file used for the transformation by making  use of <a href="http://www.altova.com/mapforce.html">Altova MapForce</a>.<br />
However, MapForce can do a lot more then this simple XML to XML mapping. <span id="more-1767"></span> One of the things it can do is map CSV directly to (advanced) XML. This can&#8217;t be done with just a XSL translation anymore, but MapForce can generate Java code to perform the transformation at runtime. In this post I will show how you can use MapForce to generate the code. In a next post I will show you how to combine this generated code with the <a href="http://www.mulesoft.org/">Mule ESB</a> as a <a href="http://www.mulesoft.org/documentation/display/MULE2USER/Creating+Custom+Transformers">transformer</a>.</p>
<p>The CSV file for this example looks like:</p>
<blockquote><p>
<code>firstname|lastname|city|country<br />
Steve|Jobs|Cupertino|USA<br />
Bill|Gates|Washington|USA<br />
Pascal|Alma|Papendrecht|Netherlands</code>
</p></blockquote>
<p>As you can see a pipe-separated file with labels at the first row. When we add it to MapForce as an input source we configure it like:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-csv.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-csv-300x260.png" alt="" title="mapforce-csv" width="300" height="260" class="alignnone size-medium wp-image-1784" /></a></p>
<p>The XSD to which the CSV file has to be mapped looks like:<br />
<img src="http://www.redstream.nl/wp-content/uploads/2010/05/customer-xsd.png" alt="" title="customer-xsd" width="402" height="216" class="alignnone size-full wp-image-1779" /></p>
<p>In MapForce this target is configured like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-xsd.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-xsd-277x300.png" alt="" title="mapforce-xsd" width="277" height="300" class="alignnone size-medium wp-image-1785" /></a></p>
<p>The mapping in MapForce is quite simple and looks like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-mapping.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-mapping-300x157.png" alt="" title="mapforce-mapping" width="300" height="157" class="alignnone size-medium wp-image-1786" /></a></p>
<p>The output of the mapping can be viewed in MapForce (by pressing the &#8220;Output&#8221; tab) and looks like this (for this particular input file):<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-mapping-result.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-mapping-result-242x300.png" alt="" title="mapforce-mapping-result" width="242" height="300" class="alignnone size-medium wp-image-1787" /></a></p>
<p>To perform this transformation in a Java environment we&#8217;ll generate Java code, after setting the package name that is generated by MapForce:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-mapping-setting.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-mapping-setting-300x165.png" alt="" title="mapforce-mapping-setting" width="300" height="165" class="alignnone size-medium wp-image-1788" /></a></p>
<p>The code that is generated by MapForce looks like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/generated-sources.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/generated-sources-179x300.png" alt="" title="generated-sources" width="179" height="300" class="alignnone size-medium wp-image-1789" /></a></p>
<p>As you can see, two packages are generated:</p>
<ul>
<li>com.altova</li>
<p>The &#8216;com.altova&#8217; package contains &#8216;generic&#8217; code that is necessary for each MapForce mapping in Java. It contains global types, functions and so on.</p>
<li>nl.redstream</li>
<p> The &#8216;nl.redstream&#8217; package is the package name we configured. This one contains the code that is specific for our mapping.
</ul>
<p>Beside these packages a Eclipse project file is generated and a Ant build script. To build this Java code you can run Ant with the following command:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/ant-jar.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/ant-jar-300x152.png" alt="" title="ant-jar" width="300" height="152" class="alignnone size-medium wp-image-1790" /></a></p>
<p>To run the code after you build it you can use the following command:<br />
<code>java nl.redstream.CustomerMappingApplication</code></p>
<p>You will get a Frame like this:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-application.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/mapforce-application-300x254.png" alt="" title="mapforce-application" width="300" height="254" class="alignnone size-medium wp-image-1791" /></a></p>
<p>Unfortunately by using the generated Main classes, the transformation can only be done on the files that where used as input for the mapping in this code. In the next post I will show how to use this generated code and use it as a Transformer in our Mule application.</p>
<p>For a lot more info about the Java generation possiblities of MapForce look <a href="http://manual.altova.com/Mapforce/mapforce-professional/index.html?cggeneratingjavacode.htm">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Issues when making use of XML (part 4)</title>
		<link>http://www.redstream.nl/2010/03/21/issues-when-making-use-of-xml-part-4/</link>
		<comments>http://www.redstream.nl/2010/03/21/issues-when-making-use-of-xml-part-4/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 07:22:08 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Functional]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1616</guid>
		<description><![CDATA[XML is quite common nowadays, especially in the application integration business that I am involved in. However, I still see companies making big mistakes when they decide to start using XML (for example as the exchange format with their business &#8230; <a href="http://www.redstream.nl/2010/03/21/issues-when-making-use-of-xml-part-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F03%2F21%2Fissues-when-making-use-of-xml-part-4%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F03%2F21%2Fissues-when-making-use-of-xml-part-4%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>XML is quite common nowadays, especially in the application integration business that I am involved in. However, I still see companies making big mistakes when they decide to start using XML (for example as the exchange format with their business partners). This series of posts is about mistakes (or at least clumsiness) in using XML that I noticed during several projects.</p>
<p><strong>No use of versions in namespaces</strong><span id="more-1616"></span></p>
<p>In the <a href="http://www.redstream.nl/2010/03/02/issues-when-making-use-of-xml-part-3/">previous</a> post I already explained the usefulness of using namespaces in your XML schemas. The next improvement would be to make a version number be part of the namespace. Imagine if you don&#8217;t do that and you have to modify your schema. And with modifying I mean a serious change like adding a mandatory element to your schema. If you make this change then all systems and clients using your schema for their interaction will fail to do so as long as they haven&#8217;t changed their side of the interface. So actually you are forcing others to make modifications to their system. If I were a client of such a supplier I would definitely be unhappy with this kind of actions.<br />
A nice way to avoid this situation is when you add a version number in the namespace of your schema. In that case you can create a new schema with a new namespace.<br />
For example, the old situation:</p>
<blockquote><p>xmlns:tns=&#8221;http://www.redstream.nl/message</p></blockquote>
<p>becomes</p>
<blockquote><p>xmlns:tns=&#8221;http://www.redstream.nl/message/v01_0</p></blockquote>
<p>Now you can let the users of your schema decide when they are going to use the newer version. Of course you can provide a roadmap about when which version will become deprecated or even unusable.<br />
This post concludes the series about using XML in real life projects. There are a lot more issues to discuss but I thought these were the most relevant to share. The final thing I want to mention is that you should use XML as meaning to get at your goal, it should not be the goal itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/03/21/issues-when-making-use-of-xml-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issues when making use of XML (part 3)</title>
		<link>http://www.redstream.nl/2010/03/02/issues-when-making-use-of-xml-part-3/</link>
		<comments>http://www.redstream.nl/2010/03/02/issues-when-making-use-of-xml-part-3/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 07:21:13 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[Functional]]></category>
		<category><![CDATA[XML/ XSD/ XSLT]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1614</guid>
		<description><![CDATA[XML is quite common nowadays, especially in the application integration business that I am involved in. However, I still see companies making big mistakes when they decide to start using XML (for example as the exchange format with their business &#8230; <a href="http://www.redstream.nl/2010/03/02/issues-when-making-use-of-xml-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F03%2F02%2Fissues-when-making-use-of-xml-part-3%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F03%2F02%2Fissues-when-making-use-of-xml-part-3%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>XML is quite common nowadays, especially in the application integration business that I am involved in.  However, I still see companies making big mistakes when they decide to start using XML (for example as the exchange format with their business partners). This series of posts is about mistakes (or at least clumsiness) in using XML that I noticed during  several projects.</p>
<p><strong>Not making (useful) use of namespaces</strong><br />
<span id="more-1614"></span><br />
As blogged before I had situations where I received XML files to describe the interface file without a schema (XSD). In this situation I <em>did</em> receive a schema, actually several schemas. Unfortunately, they forgot (?) to make use of XML namespaces. In each different XSD they added a description of the same xml type &#8216;OrderType&#8217;. You can imagine the rework you have if you have to change this &#8216;OrderType&#8217;; they have to modify all XSD&#8217;s and we had to regenerate all our <a href="https://jaxb.dev.java.net/">JAXB</a> objects. It would be much better if they supplied a separate XSD for the order element, gave it a namespace and import that in the other schemas. Another big advantage of using namespace is the possibility to distinct different versions of the same schema. I will clarify this issue in the next post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/03/02/issues-when-making-use-of-xml-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

