<?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/tag/xmlxsdxslt/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>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="p25845"><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="p2584code5"><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="p25846"><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="p2584code6"><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="p25847"><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="p2584code7"><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="p25848"><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="p2584code8"><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="p256410"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p2564code10"><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="p203212"><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="p2032code12"><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="p195516"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1955code16"><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="p195517"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code" id="p1955code17"><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="p195518"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p1955code18"><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="p188024"><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="p1880code24"><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="p188025"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1880code25"><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="p188026"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1880code26"><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="p188027"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p1880code27"><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="p188028"><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="p1880code28"><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>Combining Mule with Altova MapForce</title>
		<link>http://www.redstream.nl/2010/06/03/combining-mule-with-altova-mapforce/</link>
		<comments>http://www.redstream.nl/2010/06/03/combining-mule-with-altova-mapforce/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 06:35:11 +0000</pubDate>
		<dc:creator>Pascal Alma</dc:creator>
				<category><![CDATA[MapForce]]></category>
		<category><![CDATA[Mule]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[XML/XSD/XSLT]]></category>

		<guid isPermaLink="false">http://blog.redstream.nl/?p=1753</guid>
		<description><![CDATA[As promised in our previous blog about Altova Mapforce we will show in this post how to combine the result of the generated code of Altova Mapforce with a Mule application. As we have shown before, the Java code that &#8230; <a href="http://www.redstream.nl/2010/06/03/combining-mule-with-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%2F06%2F03%2Fcombining-mule-with-altova-mapforce%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F06%2F03%2Fcombining-mule-with-altova-mapforce%2F&amp;source=redstreamlive&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As promised in our <a href="http://www.redstream.nl/2010/05/21/introducing-altova-mapforce/">previous</a> blog about <a href="http://www.altova.com/mapforce.html">Altova Mapforce</a> we will show in this post how to combine the result of the generated code of Altova Mapforce with a <a href="http://www.mulesoft.org/">Mule</a> application. As we have shown before, the Java code that is generated by MapForce is divided in two parts:</p>
<ul>
<li>one is Altova generic, so will be reused for each mapping</li>
<li>one is mapping specific so is the actual part that changes with the mapping (this package name is configurable)</li>
</ul>
<p><span id="more-1753"></span></p>
<p>We first jarred the Altova generic code and added it to our Maven repository (<a href="http://www.jfrog.org/index.php">Artifactory</a>) so we can include this in our Mule project as dependency. We removed the generated mapping-specific Java code and used the included Ant build script to create the jar file. Here is a screenshot of how it looks in Artifactory:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/05/Screen-shot-2010-05-28-at-8.15.09-AM.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/05/Screen-shot-2010-05-28-at-8.15.09-AM-300x187.png" alt="" title="ArtifactoryScreenshot" width="300" height="187" class="alignnone size-medium wp-image-1803" /></a></p>
<p>Now if we want to use Mapforce generated code, we add the following dependency to the pom:</p>

<div class="wp_codebox"><table><tr id="p175331"><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code" id="p1753code31"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.altova<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mapforce-core<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010R2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>The next step is to add the generated mapping-specific code to the project. We do this by copying the generated mapping specific code to our Mule project (in MapForce you can configure the package name to be used for the generated code so that makes it easier fitting in<br />
with the rest of the code). Here is a screenshot of the code to copy in this case:<br />
<a href="http://www.redstream.nl/wp-content/uploads/2010/06/Screen-shot-2010-06-01-at-8.16.56-AM.png"><img src="http://www.redstream.nl/wp-content/uploads/2010/06/Screen-shot-2010-06-01-at-8.16.56-AM-300x176.png" alt="" title="Screen shot 2010-06-01 at 8.16.56 AM" width="300" height="176" class="alignnone size-medium wp-image-1856" /></a></p>
<p>Then we created a Transformer class in the Mule project that calls the generated mapping code and returns the result.<br />
Here is an example of a Transformer which uses the generated code:</p>

<div class="wp_codebox"><table><tr id="p175332"><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="p1753code32"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">nl.redstream.transformers</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.altova.io.StreamInput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.altova.io.StringInput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.altova.io.StringOutput</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">nl.redstream.mapping.MappingMapTocustomer2</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.api.transformer.TransformerException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.mule.transformer.AbstractTransformer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author pascal
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CustomerCsvToXmlTransformer <span style="color: #000000; font-weight: bold;">extends</span> AbstractTransformer <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> CustomerCsvToXmlTransformer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        registerSourceType<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        registerSourceType<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>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        setReturnClass<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>.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> doTransform<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aobject+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Object</span></a> payload, <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<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> TransformerException <span style="color: #009900;">&#123;</span>
&nbsp;
        MappingMapTocustomer2 mappingToXml <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MappingMapTocustomer2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        StringOutput output <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringOutput<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;">if</span> <span style="color: #009900;">&#40;</span>payload <span style="color: #000000; font-weight: bold;">instanceof</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><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            StringInput input <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StringInput<span style="color: #009900;">&#40;</span><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><span style="color: #009900;">&#41;</span> payload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                mappingToXml.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>input, output<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%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex<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> TransformerException<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>payload <span style="color: #000000; font-weight: bold;">instanceof</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            StreamInput sInput <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StreamInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Ainputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">InputStream</span></a><span style="color: #009900;">&#41;</span> payload<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                mappingToXml.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span>sInput, output<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%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> ex<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> TransformerException<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">return</span> output.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</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></pre></td></tr></table></div>

<p>That&#8217;s it! Define the transformer as a &#8216;custom-transformer&#8217; in your Mule config and your done. You can now create and maintain all your mappings visually with MapForce.<br />
We are now looking into the capabilities that SPL (Spy Programming Language) offer, because it looks like we can generate the Mule Transformer straight from MapForce, that would even boost the producivity more!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/06/03/combining-mule-with-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>
		<item>
		<title>Issues when making use of XML (part 2)</title>
		<link>http://www.redstream.nl/2010/02/09/issues-when-making-use-of-xml-part-2/</link>
		<comments>http://www.redstream.nl/2010/02/09/issues-when-making-use-of-xml-part-2/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 07:18:42 +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=1605</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/02/09/issues-when-making-use-of-xml-part-2/">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%2F02%2F09%2Fissues-when-making-use-of-xml-part-2%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F02%2F09%2Fissues-when-making-use-of-xml-part-2%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>Only change the syntax of the CSV file (no normalization)</strong><br />
<span id="more-1605"></span><br />
With this I mean that there has been existing interfaces based on character separated values like:</p>
<blockquote><p>car-height|car-width|driver-name|driver-gender</p></blockquote>
<p>And when they start to use XML they change it to:</p>

<div class="wp_codebox"><table><tr id="p160535"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1605code35"><pre class="xml" style="font-family:monospace;"><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;car-height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/car-height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;car-width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/car-width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;driver-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/driver-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;driver-gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/driver-gender<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></pre></td></tr></table></div>

<p>More readable would be something like:</p>

<div class="wp_codebox"><table><tr id="p160536"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p1605code36"><pre class="xml" style="font-family:monospace;"><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;car<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/car<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;driver<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/driver<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></pre></td></tr></table></div>

<p>The fields concerning one entity are now grouped together, like you would do when normalize a relational database. This not only increases human readability but it also increases the chance to get to a reusable schema. With this latest example you can imagine that you can use the &#8216;car&#8217; element also in another scheme.<br />
So the tip of the day is: perform normalization in your XSD where possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/02/09/issues-when-making-use-of-xml-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issues when making use of XML (part 1)</title>
		<link>http://www.redstream.nl/2010/02/07/issues-when-making-use-of-xml-part-1/</link>
		<comments>http://www.redstream.nl/2010/02/07/issues-when-making-use-of-xml-part-1/#comments</comments>
		<pubDate>Sun, 07 Feb 2010 15:26:03 +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=1595</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/02/07/issues-when-making-use-of-xml-part-1/">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%2F02%2F07%2Fissues-when-making-use-of-xml-part-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.redstream.nl%2F2010%2F02%2F07%2Fissues-when-making-use-of-xml-part-1%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 post is about one of the mistakes I noticed during one of my projects.</p>
<p><strong>Not using a schema (<a href="http://www.w3schools.com/schema/">XSD</a>) or <a href="http://www.w3schools.com/DTD/default.asp">DTD</a></strong><br />
<span id="more-1595"></span><br />
In this situation I contacted a business partner to ask them how the XML file/message should look like if I want to communicate with them. The reply to the question was just an example XML file with the text: &#8216;it must look like this&#8217;. In this case there is no way to check if the XML is valid according to their specs and it is unknown if it can be processed by the other party.<br />
Although <em>they</em> might check the xml very well when they process it, it would be much better if I could do some checking at our side. It would reduce the network traffic and increase the performance a lot. Also using Object-XML mapping tools like <a href="https://jaxb.dev.java.net/">JAXB</a> become difficult (or even impossible) which may working with the XML files harder in a Java environment.<br />
The final issue I want to mention is that you can&#8217;t use XML mapping tools like <a href="http://www.altova.com/mapforce.html">Altova Mapforce</a>. These tools really make your life easier if you have to transform one XML to another XML format. But they are based on XSD&#8217;s so without these you can&#8217;t create your XSLT for mapping purposes.<br />
There might be a lot more disadvantages but I think the point is clear: when using XML files make sure you have an XSD for them.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redstream.nl/2010/02/07/issues-when-making-use-of-xml-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

