<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Xatapult&#039;s XML Blog</title>
	<atom:link href="http://xatapult.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://xatapult.wordpress.com</link>
	<description>Thoughts, tips and how-to&#039;s on XML and related technologies</description>
	<lastBuildDate>Tue, 26 Apr 2011 07:13:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='xatapult.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/4174d036d3e3d618eaf2ddf85039214f?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Xatapult&#039;s XML Blog</title>
		<link>http://xatapult.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://xatapult.wordpress.com/osd.xml" title="Xatapult&#039;s XML Blog" />
	<atom:link rel='hub' href='http://xatapult.wordpress.com/?pushpress=hub'/>
		<item>
		<title>XSLT types against typos</title>
		<link>http://xatapult.wordpress.com/2011/04/26/xslt-types-against-typos/</link>
		<comments>http://xatapult.wordpress.com/2011/04/26/xslt-types-against-typos/#comments</comments>
		<pubDate>Tue, 26 Apr 2011 07:13:32 +0000</pubDate>
		<dc:creator>xatapult</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Tips and trics]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://xatapult.wordpress.com/?p=86</guid>
		<description><![CDATA[Some tiny typing mistakes in your XSLT stylesheet can cause major headaches. Why? Because they go undetected by the standard static and dynamic error checking mechanisms. Something as simple as writing /Filename where it should be /FileName will only show up if your own test/debug efforts find it and will not be trapped by the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=86&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p style="margin-top:0;margin-bottom:1px;">Some tiny typing mistakes in your XSLT stylesheet can cause major headaches. Why? Because they go undetected by the standard static and dynamic error checking mechanisms. Something as simple as writing <code style="font-size:1.2em;color:#008099;">/Filename</code> where it should be <code style="font-size:1.2em;color:#008099;">/FileName</code> will only show up if your own test/debug efforts find it and will not be trapped by the XSLT engine. Unless…<span id="more-86"></span> you use the XSLT V2.0 mechanism for type checking. </p>
<h4>What&#8217;s up?</h4>
<p style="margin-top:0;margin-bottom:1px;">Assume you have an XML document that looks like this:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;Things&gt;
   &lt;Thing thingid="12345FFD3"&gt;...&lt;/Thing&gt;
   &lt;Thing thingid="86779EAD0"&gt;...&lt;/Thing&gt;
   ...
&lt;/Things&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">In your XSLT stylesheet you have a named template that does something with a thing:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;xsl:template name="ProcessThing"&gt;
  &lt;xsl:param name="ThingId"/&gt;
  &lt;xsl:for-each select="/Things/Thing[@id eq $ThingId]"&gt;
    &lt;!-- Do something with the thing --&gt;
  &lt;/xsl:for-each&gt;
&lt;/xsl:template&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">Spot the mistake: The author of this template forgot (or didn&#8217;t know) that the identifier attribute on a thing was spelled <code style="font-size:1.2em;color:#008099;">thingid</code> and not <code style="font-size:1.2em;color:#008099;">id</code>. If you run this, no error message will show up, the for-each loop will simply not execute. Maybe you notice, maybe you don&#8217;t (because it was embedded somewhere in a very complicated transformation…). The same for all spelling mistakes in element/attribute names in XPath expressions (like <code style="font-size:1.2em;color:#008099;">/Things/thing[@thingid eq $ThingId]</code>).</p>
<p style="margin-top:0;margin-bottom:1px;">Not nice at all: Your code went into production, the spelling mistake prevented an important part of some calculation from happening. Because of this the client paid too much taxes and now he/she can&#8217;t pay you…</p>
<h4>Preventive measures</h4>
<p style="margin-top:0;margin-bottom:1px;">So what can you do? Double check, reread, ferocious debugging, keep fingers crossed, pray… certainly, do it all! But what you really (should) want is the bug to show up in a booming error message. Here is how to do this using the XSLT V2.0 type mechanism (this won&#8217;t work in V1.0).</p>
<p style="margin-top:0;margin-bottom:1px;">XSLT V2.0 is type aware. You can specify what data type a variable (or parameter) must have for it to be valid. Although this certainly is no panacea for all mistakes, typing errors in XPath expressions can be caught by it.</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">For instance, if you rewrite the above example as this, the error will show up immediately:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;xsl:template name="ProcessThing"&gt;
  &lt;xsl:param name="ThingId"/&gt;
  &lt;xsl:variable name="ThingToProcess" as="element(Thing)"
    select="/Things/Thing[@id eq $ThingId]"/&gt;
  &lt;xsl:for-each select="$ThingToProcess"&gt;
    &lt;!-- Do something with the thing --&gt;
  &lt;/xsl:for-each&gt;
&lt;/xsl:template&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">At runtime, the stylesheet processor will notice that <code style="font-size:1.2em;color:#008099;">/Things/Thing[@id eq $ThingId]</code> does not return the expected <code style="font-size:1.2em;color:#008099;">&lt;Thing&gt;</code> element but the empty set and will complain about it.</p>
<p style="margin-top:0;margin-bottom:1px;">There is even a bonus: If the input document contains an error and has two things with the same id an error will show up also: The <code style="font-size:1.2em;color:#008099;">$ThingToProcess</code> variable can only contain a <i>single</i> thing, not multiple!</p>
<p style="margin-top:0;margin-bottom:1px;">To make this template even better, I would personally also type the parameter:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;xsl:param name="ThingId" as="xs:string" required="yes"/&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">This traps forgetting the parameter (because of the <code style="font-size:1.2em;color:#008099;">required="yes"</code>) and also passing empty or multiple values.</p>
<h4>Trapping mistakes in the input document</h4>
<p style="margin-top:0;margin-bottom:1px;">The &#8220;types against typos&#8221; mechanism can also be used in trapping input document mistakes. (This assumes that you haven&#8217;t validated your input document, which is of course the best way to do this, but you know how it is…).</p>
<p style="margin-top:0;margin-bottom:1px;">Before using anything, put them in a typed variable first:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;xsl:variable name="Status" as="xs:string" select="@status"/&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">No attribute means no value (which differs from the empty string!) and an error will stop the stylesheet.</p>
<p> </p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xatapult.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xatapult.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/xatapult.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/xatapult.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xatapult.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xatapult.wordpress.com/86/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xatapult.wordpress.com/86/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xatapult.wordpress.com/86/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=86&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://xatapult.wordpress.com/2011/04/26/xslt-types-against-typos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/55a98e2701203f29b4f4ab3ce731d4d8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">xatapult</media:title>
		</media:content>
	</item>
		<item>
		<title>Naming namespaces</title>
		<link>http://xatapult.wordpress.com/2010/03/31/naming-namespaces/</link>
		<comments>http://xatapult.wordpress.com/2010/03/31/naming-namespaces/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 05:55:37 +0000</pubDate>
		<dc:creator>xatapult</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Standards and guidelines]]></category>

		<guid isPermaLink="false">http://xatapult.wordpress.com/?p=83</guid>
		<description><![CDATA[Namespaces are inevitable when you work with XML. In the beginning they seem awkward and unnecessary, but after a while you find out that they have a purpose and are actually very useful. When you start designing your own XML, sooner or later you&#8217;ll want your own namespace too. And there an important question arises: [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=83&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p style="margin-top:0;margin-bottom:1px;">Namespaces are inevitable when you work with XML. In the beginning they seem awkward and unnecessary, but after a while you find out that they have a purpose and are actually very useful. </p>
<p style="margin-top:0;margin-bottom:1px;">When you start designing your own XML, sooner or later you&#8217;ll want your own namespace too. And there an important question arises: How to call your namespace, what name should your namespace have?</p>
<p style="margin-top:0;margin-bottom:1px;">There are customs and, as usual, many opinions about this. Let me add mine…<span id="more-83"></span></p>
<h4>Namespace basics</h4>
<p style="margin-top:0;margin-bottom:1px;">Before going to the actual subject, let&#8217;s do a quick recap on namespaces.</p>
<p style="margin-top:0;margin-bottom:1px;">The main reason for namespaces is to differentiate between several types of XML in the same document. It&#8217;s handy for avoiding element and attribute name clashes and makes their meaning more clear. Here is a classic example: Assume you&#8217;re in an XML document about a book and the following element appears:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;name&gt;Johnny Johnson&lt;/name&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">Is this the name of a book? Or an author? Or a publisher? Adding a namespace clarifies this:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;name xmlns="authornamesnamespace"&gt;Johnny Johnson&lt;/name&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">Another classic example is the envelope-content construction as used, for instance, in SOAP messaging:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:msg="mymessagenamespace"&gt;
  &lt;soapenv:Header&gt;
   […]
  &lt;/soapenv:Header&gt;
  &lt;soapenv:Body&gt;
    &lt;msg:MyMessage&gt;Hello world!&lt;/msg:MyMessage&gt;
  &lt;/soapenv:Body&gt;
&lt;/soapenv:Envelope&gt;
</pre>
<p>
<h4>Prefix and name</h4>
<p style="margin-top:0;margin-bottom:1px;">Never confuse the <i>namespace prefix</i> in an XML document with the <i>namespace name</i>. In the example above <code style="font-size:1.2em;color:#008099;">soapenv</code> is the namespace prefix for the namespace with the name <code style="font-size:1.2em;color:#008099;"><a href="http://schemas.xmlsoap.org/soap/envelope/" target="_blank">schemas.xmlsoap.org/soap/envelope/</a></code>. </p>
<p style="margin-top:0;margin-bottom:1px;">Changing the prefix is no problem. You can use anything you like (within the rules of a no-colon-name, an <code style="font-size:1.2em;color:#008099;">NCName</code>). For instance, this means exactly the same:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;bettyboop:Envelope xmlns:bettyboop="http://schemas.xmlsoap.org/soap/envelope/" […]
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">However, changing the namespace name is not allowed. Your SOAP software will no longer recognize your messages if you do something like:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;soapenv:Envelope xmlns:soapenv="somethingilikemore"
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">It expects the envelope to be in the right namespace and so it should be!</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">So, what you choose for a prefix is not important (at least not for the meaning of your document, it can be important for its legibility), but choosing a correct namespace name is!</p>
<h4>What&#8217;s in a name?</h4>
<p style="margin-top:0;margin-bottom:1px;">As long as a namespace name complies with the syntactic rules for a URI, you can name a namespace anything you like. It&#8217;s just a string of characters and nothing stops you from calling your namespace <code style="font-size:1.2em;color:#008099;">mumbledumbledoozydoe</code>. </p>
<p style="margin-top:0;margin-bottom:1px;">However, the reason domain names (like <code style="font-size:1.2em;color:#008099;">xmlsoap.org</code>) are often used inside namespace names, is that it makes the namespace globally unique. This is piggy-backing on the existing mechanism for the registration of domain names: This ensures that nobody in the world can register a namespace already belonging to somebody else. Ergo, a domain name is globally unique and so a namespace using the domain name is globally unique also.</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">So its wise to use your domain name inside a namespace name when your XML is send out into the big wide world.</p>
<h4>Naming conventions for namespaces</h4>
<p style="margin-top:0;margin-bottom:1px;">There are several conventions for naming namespaces, but the most widely used is one that looks like a web address or URL. Examples are everywhere:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">http://schemas.xmlsoap.org/soap/envelope/

http://www.w3.org/1999/XSL/Transform

http://www.w3.org/1999/xhtml

http://www.w3.org/2001/XMLSchema
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">I know its fighting windmills, but I am very strongly opposed to this convention. Why? Well, because we are using things that look like web addresses for things that aren&#8217;t web addresses at all. A namespace is <i>not</i> a web address, it&#8217;s a namespace!</p>
<p style="margin-top:0;margin-bottom:1px;">What do you think when you see a namespace formatted like this for the first time? Exactly, that it is a URL. It creates a mental barrier understanding what this is all about. I must admit that I have suffered from this myself. But I also train people in XML basics and the concept of namespaces is very hard to explain <i>because</i> of this URL convention.</p>
<p style="margin-top:0;margin-bottom:1px;">So IMHO this is a silly convention, unnecessary complicating a very simple concept. We should stop using it.</p>
<h4>An alternative</h4>
<p style="margin-top:0;margin-bottom:1px;">Ok, but what should we use instead? A good naming convention for namespaces must have two characteristics:</p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>It must be clear from the start that it is a namespace and not something else.</li>
<li>It must be easy to make a namespace globally unique</li>
</ul>
<p>
<p style="margin-top:0;margin-bottom:1px;">To accomplish this, I propose the following convention (for which the general structure was stolen from the standard for a URN):</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">ns:{domain name}:{further information}
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">For instance:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">ns:xatapult.nl:generic
ns:myowndomain.com:storage.text.specials
ns:html8.org:linking
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">There: simple, straight and it cannot be mistaken for something else. </p>
<p> </p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xatapult.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xatapult.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/xatapult.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/xatapult.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xatapult.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xatapult.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xatapult.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xatapult.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=83&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://xatapult.wordpress.com/2010/03/31/naming-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/55a98e2701203f29b4f4ab3ce731d4d8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">xatapult</media:title>
		</media:content>
	</item>
		<item>
		<title>XML Coding Standards</title>
		<link>http://xatapult.wordpress.com/2010/01/08/xml-coding-standards/</link>
		<comments>http://xatapult.wordpress.com/2010/01/08/xml-coding-standards/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 10:03:25 +0000</pubDate>
		<dc:creator>xatapult</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Opinion]]></category>
		<category><![CDATA[Standards and guidelines]]></category>
		<category><![CDATA[Standards]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://xatapult.wordpress.com/?p=79</guid>
		<description><![CDATA[Looking at the XML that is around, everybody seems to use different standards for element and attribute names. Some people write their elements in all uppercase, like &#60;USERNAME&#62;, some use UpperCamelCase, like &#60;UserName&#62;, or lowerCamelCase, like &#60;userName&#62;. Some standards, like XSLT, use all lowercase, like &#60;xsl:value-of&#62;. There is no uniformity, in contrast to, for instance, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=79&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p style="margin-top:0;margin-bottom:1px;">Looking at the XML that is around, everybody seems to use different standards for element and attribute names. Some people write their elements in all uppercase, like <code style="font-size:1.2em;color:#008099;">&lt;USERNAME&gt;</code>, some use UpperCamelCase, like <code style="font-size:1.2em;color:#008099;">&lt;UserName&gt;</code>, or lowerCamelCase, like <code style="font-size:1.2em;color:#008099;">&lt;userName&gt;</code>. Some standards, like XSLT, use all lowercase, like <code style="font-size:1.2em;color:#008099;">&lt;xsl:value-of&gt;</code>. There is no uniformity, in contrast to, for instance, Java, where everybody more or less adheres to the same writing and coding rules.</p>
<p style="margin-top:0;margin-bottom:1px;">So should we have a standard and what should it look like? Let&#8217;s explore.<span id="more-79"></span></p>
<h4>Why coding standards?</h4>
<p style="margin-top:0;margin-bottom:1px;">Before writing this Blog I re-consulted the excellent book<i> &#8220;C Style: Standards and guidelines&#8221;</i> by David Straker, written in 1992. The C programming language might be a bit out of fashion, the general parts of the book still hold. David Straker thoroughly answers questions like: Why do we need standards and what should these look like.</p>
<p style="margin-top:0;margin-bottom:1px;">I will not repeat all he has to say about it, but the baseline is: Coding standards are for humans. To make life as a designer/programmer easier. To make things more understandable for somebody else (or yourself when you revisit the code after a year or so). </p>
<p style="margin-top:0;margin-bottom:1px;">A good standard takes human psychological limitations into account. For instance, computers don&#8217;t give a damn, but for humans <code style="font-size:1.2em;color:#008099;">&lt;CustomerContactPersonUsernameCodeAbbreviation&gt;</code> is easier to read than <code style="font-size:1.2em;color:#008099;">&lt;customercontactpersonusernamecodeabbreviation&gt;</code>. And a standard with just a few (good) rules is easier to follow than an extensive document with umpteen pages.</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">How exactly do (well designed!) coding standards help?</p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>As a designer/programmer, you no longer have to think about simple things. Thoughts like &#8220;Shall I write this in upper or lower case?&#8221;, &#8220;I created something like this a week ago; .I want to stay consistent, so what rules did I use to name it?&#8221;. In short, it frees parts of your mind to think about more important things.</li>
<li>Reading somebody else&#8217;s designs or programs or whatever becomes much easier: You can recognize things in the way they are written or layed-out.</li>
</ul>
<h4>What shall we standardize?</h4>
<p style="margin-top:0;margin-bottom:1px;">Just a few lists with things we might (or might not) standardize:</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">Basic XML:</p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Basic naming rules for elements and attributes</li>
<li>For common types/usages prefixes or suffixes? For instance, I end the names of attributes that hold an identifier always with <code style="font-size:1.2em;color:#008099;">id</code> (e.g. <code style="font-size:1.2em;color:#008099;">userid="…"</code>) and attributes that <i>refer</i> to an identifier with <code style="font-size:1.2em;color:#008099;">idref</code> (e.g. <code style="font-size:1.2em;color:#008099;">currentuseridref="…"</code>)</li>
<li>Namespace names (and prefix?)</li>
<li>Maybe lay-out for comments…?</li>
</ul>
<p>
<p style="margin-top:0;margin-bottom:1px;">XML Schema (XSD):</p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Type and group names (maybe something that distinguishes between simple and complex types, attribute and element groups)</li>
<li>Versioning of schemas (a very tricky subject)</li>
<li>Usage of container elements on repeating data (do you <i>always</i> need a <code style="font-size:1.2em;color:#008099;">&lt;Customers&gt;</code> element around multiple <code style="font-size:1.2em;color:#008099;">&lt;Customer&gt;</code> records?)</li>
</ul>
<p>
<p style="margin-top:0;margin-bottom:1px;">XML Transformations (XSLT):</p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Variable/Parameter names</li>
<li>Named template names (and for XSLT 2.0: functions)</li>
<li>Modes</li>
<p></ul>
<p>
<p style="margin-top:0;margin-bottom:1px;">And so on, and so forth.</p>
<h4>My standards</h4>
<p style="margin-top:0;margin-bottom:1px;">The way I design and write my XML is (after all these years) still developing. However, some things seem to have settled. For what its worth:</p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Element names in UpperCamelCase (<code style="font-size:1.2em;color:#008099;">&lt;UserName&gt;</code>, <code style="font-size:1.2em;color:#008099;">&lt;CarModel&gt;</code>)</li>
<li>Attributes in all lowercase (<code style="font-size:1.2em;color:#008099;">username</code>, <code style="font-size:1.2em;color:#008099;">isvalid</code>)</li>
<li>An attribute that is an identifier ends with <code style="font-size:1.2em;color:#008099;">id</code> (<code style="font-size:1.2em;color:#008099;">userid</code>, <code style="font-size:1.2em;color:#008099;">carid</code>)</li>
<li>An attribute that is a reference to an identifier ends with <code style="font-size:1.2em;color:#008099;">idref</code> (<code style="font-size:1.2em;color:#008099;">currentuseridref</code>, <code style="font-size:1.2em;color:#008099;">modelidref</code>)</li>
<li>For XML schemas I use &#8220;Hungarian style&#8221; prefixes like <code style="font-size:1.2em;color:#008099;">t</code> for a simple type, <code style="font-size:1.2em;color:#008099;">ct</code> for a complex type, <code style="font-size:1.2em;color:#008099;">g</code> for a group, etc.</li>
<li>In XML Transformations elements (variables, templates, etc.) I use the UpperCamelCase convention. Modes always start with the word <code style="font-size:1.2em;color:#008099;">Mode</code>.</li>
</ul>
<p>
<p style="margin-top:0;margin-bottom:1px;">To stay consistent, I have a document (which has the permanent status &#8220;working copy&#8221;, or &#8220;in progress&#8221;) in which I, now and then, write these kinds of things down. For me it&#8217;s the only way not to forget what I have decided about these things in the past.</p>
<h4>Bottom line</h4>
<p style="margin-top:0;margin-bottom:1px;">IMHO:</p>
<p style="margin-top:0;margin-bottom:1px;">A standard, even a simple one, is better than none at all.</p>
<p style="margin-top:0;margin-bottom:1px;">Some standards are better than others.</p>
<p style="margin-top:0;margin-bottom:1px;">Creating a good standard is balancing between too much and too little.</p>
<p style="margin-top:0;margin-bottom:1px;">Its not necessary to have a &#8220;global&#8221; standard, but each company that is serious about its XML should have one.</p>
<p> </p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xatapult.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xatapult.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/xatapult.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/xatapult.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xatapult.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xatapult.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xatapult.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xatapult.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=79&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://xatapult.wordpress.com/2010/01/08/xml-coding-standards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/55a98e2701203f29b4f4ab3ce731d4d8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">xatapult</media:title>
		</media:content>
	</item>
		<item>
		<title>Interpreting XML &#8211; Dont do it yourself!</title>
		<link>http://xatapult.wordpress.com/2009/10/08/interpreting-xml-dont-do-it-yourself/</link>
		<comments>http://xatapult.wordpress.com/2009/10/08/interpreting-xml-dont-do-it-yourself/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 09:07:13 +0000</pubDate>
		<dc:creator>xatapult</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://xatapult.wordpress.com/?p=65</guid>
		<description><![CDATA[In an XML document you can express the same semantics in syntactically very different ways. Which is a difficult way of saying: Watch out, XML documents may look different but can nonetheless mean the same! If you use the right tools to parse and interpret the XML that is not a problem. However, be aware [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=65&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p style="margin-top:0;margin-bottom:1px;">In an XML document you can express the same semantics in syntactically very different ways. Which is a difficult way of saying: Watch out, XML documents may look different but can nonetheless mean the same! If you use the right tools to parse and interpret the XML that is not a problem. However, be aware for developers that do not…</p>
<p style="margin-top:0;margin-bottom:1px;">This article explores the areas that cause most of the confusion in interpreting XML.<span id="more-65"></span></p>
<h4>True stories</h4>
<p style="margin-top:0;margin-bottom:1px;">This really happened: One of the companies I worked with had to interpret SOAP XML messages coming from another company. Unfortunately they decided to use <i>regular expressions</i> (no, this is not a joke) to interpret the XML! </p>
<p style="margin-top:0;margin-bottom:1px;">Of course in the beginning all went well. The XML messages came in, the regular expressions parsed them and miraculously produced the right results. Until… the company that sent the messages decided to upgrade their SOAP framework. After this the same messages were sent but the regular expression were no longer doing their job. </p>
<p style="margin-top:0;margin-bottom:1px;">I can&#8217;t remember exactly what the new framework did, but it was a completely innocent thing with regards to the <i>meaning</i> of the messages. Something like an extra line break in between elements, a different namespace prefix, a different way of declaring namespaces or changing the order of the attributes. Nothing a true XML parser would have worried about, but the regular expressions stopped working.</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">Another example was an application that suddenly refused to handle a valid XML document because a namespace prefix was introduced (instead of using a default namespace). In this case a XML parser was used, but the handling of namespaces was definitely not correct.</p>
<h4>Namespaces</h4>
<p style="margin-top:0;margin-bottom:1px;">Very often problems interpreting the XML are due to the handling of namespaces. Have a look at the examples below:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;data xmlns="basenamespace" xmlns:e="embeddednamespace"&gt;
   &lt;e:content&gt;bla bla bla&lt;/e:content&gt;
&lt;/data&gt;
</pre>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;data xmlns="basenamespace" &gt;
   &lt;content xmlns="embeddednamespace"&gt;bla bla bla&lt;/content&gt;
&lt;/data&gt;
</pre>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;b:data xmlns:b="basenamespace" xmlns:whatever="embeddednamespace"&gt;
   &lt;whatever:content&gt;bla bla bla&lt;/whatever:content&gt;
&lt;/b:data&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">As you might have guessed or seen, these examples all <i>mean</i> the same, albeit the different syntax. The following example however means something completely different, although at first glance it looks the same:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;data xmlns="basenamespace" xmlns:e="embeddednamespace"&gt;
   &lt;content&gt;bla bla bla&lt;/content&gt;
&lt;/data&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">Missed it? In the first three examples the inner <code style="font-size:1.2em;color:#008099;">&lt;content&gt;</code> element was in the namespace <code style="font-size:1.2em;color:#008099;">embeddednamespace</code>. In the last example it was in the <code style="font-size:1.2em;color:#008099;">basenamespace</code> namespace. The last example did declare the <code style="font-size:1.2em;color:#008099;">embeddednamespace</code> namespace but does not use it, something which might be confusing but is perfectly valid.</p>
<p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Use an XML parser that can handle namespaces and all the variations in their declarations. Most can but some older or very simple ones do not (examples are the basic XML parsers in PHP and Perl).</li>
<li>Always take the namespace of an element or attribute into account when interpreting the XML.</li>
<li>Never ever use the namespace prefix (or the absence of it) to distinguish between namespaces. Always use the full namespace name.</li>
<li>Do not get confused by the declaration of superfluous namespaces.</li>
</ul>
<h4>Text</h4>
<p style="margin-top:0;margin-bottom:1px;">Text is just text you might think. However it is not. Have a look at the following examples which all mean exactly the same (<b>WATCH OUT:</b> I inserted a space right before every entity ending semicolon. Otherwise WordPress will not display everything correct. Remove this space to try the examples):</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;p&gt;What are you looking at?&lt;/p&gt;
&lt;p&gt;&lt;![CDATA[What are you looking at?]]&gt;&lt;/p&gt;
&lt;p&gt;What are you looking at&lt;![CDATA[?]]&gt;&lt;/p&gt;
&lt;p&gt;What are you looking at&amp;#x3F ;&lt;/p&gt;
&lt;p&gt;What are you looking at&amp;#x3f ;&lt;/p&gt;
&lt;p&gt;&amp;#x57 ;&amp;#x68 ;&amp;#x61 ;&amp;#x74 ;&amp;#x20 ;&amp;#x61 ;&amp;#x72 ;&amp;#x65 ;&amp;#x20 ;
&amp;#x79 ;&amp;#x6F ;&amp;#x75 ;&amp;#x20 ;&amp;#x6C ;&amp;#x6F ;&amp;#x6F ;&amp;#x6B ;&amp;#x69 ;
&amp;#x6E ;&amp;#x67 ;&amp;#x20 ;&amp;#x61 ;&amp;#x74 ;&amp;#x3F ;&lt;/p&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">So reading text is not straight forward. It might contain entities or CDATA sections and these must be handled well.</p>
<h4>Whitespace</h4>
<p style="margin-top:0;margin-bottom:1px;">Handling whitespace is a very tricky area. Whether or not it is important relies on the nature of the XML. In data oriented XML, whitespace in between elements is usually not significant. Probably (but we cannot be absolutely sure just looking at the XML) the following two examples mean the same:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;codes&gt;&lt;code&gt;code1&lt;/code&gt;&lt;code&gt;code2&lt;/code&gt;&lt;/codes&gt;
</pre>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;codes&gt;
   &lt;code&gt;code1&lt;/code&gt;
   &lt;code&gt;code2&lt;/code&gt;
&lt;/codes&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">But what about these more text oriented examples?</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;p&gt;&lt;b&gt;bold&lt;/b&gt; &lt;i&gt;italic&lt;/i&gt; &lt;u&gt;underline&lt;/u&gt;&lt;/p&gt;
</pre>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;p&gt;
   &lt;b&gt;bold&lt;/b&gt;
   &lt;i&gt;italic&lt;/i&gt;
   &lt;u&gt;underline&lt;/u&gt;
&lt;/p&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">Again, it depends on how the XML is used. </p>
<p>
<ul style="margin-top:0;margin-bottom:1px;">
<li>When processing data oriented XML, whitespace in between elements is usually not significant and can be discarded. This also allows pretty printers to make the XML more readable without changing its meaning.</li>
<li>In more text oriented XML, things get more difficult. Be aware that whitespace in between elements might be significant. </li>
</ul>
<h4>Other pitfalls</h4>
<ul style="margin-top:0;margin-bottom:1px;">
<li>The <i>order of attributes</i> is not significant. <code style="font-size:1.2em;color:#008099;">&lt;hello type="greeting" meaning="friendly"/&gt;</code> is the same as <code style="font-size:1.2em;color:#008099;">&lt;hello meaning="friendly" type="greeting/&gt;</code>.</li>
<li>XML is <i>case sensitive</i>. <code style="font-size:1.2em;color:#008099;">&lt;Hello/&gt;</code> is not the same as <code style="font-size:1.2em;color:#008099;">&lt;hello/&gt;</code> or <code style="font-size:1.2em;color:#008099;">&lt;HELLO/&gt;</code>.</li>
<li>Attributes can be enclosed in single or double quotes. <code style="font-size:1.2em;color:#008099;">&lt;hello type="greeting"/&gt;</code> is the same as <code style="font-size:1.2em;color:#008099;">&lt;hello type='greeting'/&gt;</code></li>
</ul>
<p style="margin-top:0;margin-bottom:1px;">And probably numerous others. If you have anything to add I would like to hear from you.</p>
<h4>Conclusion</h4>
<p style="margin-top:0;margin-bottom:1px;">Unless you are in the business of writing XML parsers (and not many are), don&#8217;t try to do it yourself. Most development environments have excellent software on board to do it for you. After the parsing you can access the XML using SAX or DOM or some custom interface.</p>
<p style="margin-top:0;margin-bottom:1px;">XML looks simple but has an awful lot of nitty-gritty details you need to take care of interpreting it. And never rely on simple string parsing…</p>
<p> </p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xatapult.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xatapult.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/xatapult.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/xatapult.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xatapult.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xatapult.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xatapult.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xatapult.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=65&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://xatapult.wordpress.com/2009/10/08/interpreting-xml-dont-do-it-yourself/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/55a98e2701203f29b4f4ab3ce731d4d8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">xatapult</media:title>
		</media:content>
	</item>
		<item>
		<title>Schema references</title>
		<link>http://xatapult.wordpress.com/2009/09/09/schema-references/</link>
		<comments>http://xatapult.wordpress.com/2009/09/09/schema-references/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 12:43:58 +0000</pubDate>
		<dc:creator>xatapult</dc:creator>
				<category><![CDATA[How-to]]></category>
		<category><![CDATA[Schema]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSD]]></category>

		<guid isPermaLink="false">http://xatapult.wordpress.com/?p=57</guid>
		<description><![CDATA[How do you associate a schema with an XML document? It&#8217;s easy but the details also easily forgotten. A summary and a how-to. Why? You have an XML document and wants it validated against one or more W3C XML schemas. How do you tell the validator which schemas to use? Your XML editor can display [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=57&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p style="margin-top:0;margin-bottom:1px;">How do you associate a schema with an XML document? It&#8217;s easy but the details also easily forgotten. A summary and a how-to.<span id="more-57"></span></p>
<h4>Why?</h4>
<ul style="margin-top:0;margin-bottom:1px;">
<li>You have an XML document and wants it validated against one or more W3C XML schemas. How do you tell the validator which schemas to use?</li>
<li>Your XML editor can display useful hints and prevent creating invalid documents when it knows which schemas to use.</li>
</ul>
<h4>How?</h4>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Associations between XML documents and W3C XML Schemas are created by adding specific attributes in the <code style="font-size:1.2em;color:#008099;"><strong><a href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">www.w3.org/2001/XMLSchema-instance</a></strong></code> namespace.</li>
<li>To be able to do this, you have to specify this namespace in your XML document, usually on the root element:</li>
</ul>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" …&gt;
    …
&lt;/RootElement&gt;</pre>
<ul style="margin-top:0;margin-bottom:1px;">
<li>The usual namespace prefix is <code style="font-size:1.2em;color:#008099;">xsi</code>. Better stick to this to avoid confusion.</li>
<li>Use the <code style="font-size:1.2em;color:#008099;">xsi:noNamespaceSchemaLocation</code> to specify the location of a schema file for the part(s) of your document that have no namespace attached (or when you don&#8217;t use namespaces at all):</li>
</ul>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://bogus.com/schemas/schemaforthisdocument.xsd"
    …
&gt;
   …
&lt;/RootElement&gt;</pre>
<ul style="margin-top:0;margin-bottom:1px;">
<li>The <code style="font-size:1.2em;color:#008099;">xsi:noNamespaceSchemaLocation</code> attribute is put on the root element. Only in pathological circumstances (non-namespaced inside namespaced XML) you might have a reason to put it elsewhere.</li>
<li>For namespaces, use the <code style="font-size:1.2em;color:#008099;">xsi:schemaLocation</code> attribute. The content of this attribute consists of pairs of (namespace-name; schema-location-for-this-namespace), all separated by whitespace. For instance:</li>
</ul>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;RootElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="namespace1 schema-location-for-namespace1
                        namespace2 schema-location-for-namespace2
                        …"
   …
&gt;
   …
&lt;/RootElement&gt;</pre>
<ul style="margin-top:0;margin-bottom:1px;">
<li>There are several strategies where to put <code style="font-size:1.2em;color:#008099;">xsi:schemaLocation</code> attribute(s):</li>
<li style="text-indent:1em;">You can use a single <code style="font-size:1.2em;color:#008099;">xsi:schemaLocation</code> attribute on the root element, specifying all namespaces and schema locations. Since namespaces and schema locations are usually long strings, this will soon become very unreadable.</li>
<li style="text-indent:1em;">You can use an <code style="font-size:1.2em;color:#008099;">xsi:schemaLocation</code> attribute on the first occurrence of an element/attribute in a specific namespace, specifying only the association for this particular namespace. This is cleaner but spreads the information on associated schemas all over your document.</li>
<li style="text-indent:1em;">You can make a mess of it by mixing both approaches or by specifying locations on elements that have nothing to do with the namespace involved. The tools won&#8217;t mind but readers will.</li>
</ul>
<h4>Pitfalls and peculiarities?</h4>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Values in the <code style="font-size:1.2em;color:#008099;">xsi:…</code> attributes have the official status of <em>hints</em> to the schema processor. So they can be ignored, treated wrong or overridden by something else.</li>
<li>Some tools have a tool-specific way to associate a document with its schemas. This usually overrides the values set in the <code style="font-size:1.2em;color:#008099;">xsi:…</code> attributes, since these are only hints…</li>
<li>If the schema locations contain relative path information, this is resolved against the location of the XML document. So be careful how you specify the file locations if you ever plan to move your documents elsewhere. Unless of course you always transfer your documents and schemas in one go.</li>
<li>The contents of the <code style="font-size:1.2em;color:#008099;">xsi:schemaLocation</code> attribute very soon becomes a hard to interpret visual mess. You can hand-edit it nicely (as in the examples) but an XML pretty printer will undo all your hard work very quickly. Not much we can do about it…</li>
</ul>
<h4>More information?</h4>
<ul style="margin-top:0;margin-bottom:1px;">
<li>Have a look at the rather incomprehensible official specification: <a href="http://www.w3.org/TR/xmlschema-1" target="_blank">www.w3.org/TR/xmlschema-1</a></li>
<li>For a simple tutorial: <a href="http://www.w3schools.com/schema/schema_howto.asp" target="_blank">www.w3schools.com/schema/schema_howto.asp</a></li>
</ul>
<p> </p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xatapult.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xatapult.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/xatapult.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/xatapult.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xatapult.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xatapult.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xatapult.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xatapult.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=57&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://xatapult.wordpress.com/2009/09/09/schema-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/55a98e2701203f29b4f4ab3ce731d4d8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">xatapult</media:title>
		</media:content>
	</item>
		<item>
		<title>Schemas from DTDs: The root (element) of evil?</title>
		<link>http://xatapult.wordpress.com/2009/09/07/standarddtdsschemas/</link>
		<comments>http://xatapult.wordpress.com/2009/09/07/standarddtdsschemas/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 13:32:10 +0000</pubDate>
		<dc:creator>xatapult</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[DTD]]></category>
		<category><![CDATA[Schema]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XSD]]></category>

		<guid isPermaLink="false">http://xatapult.wordpress.com/?p=33</guid>
		<description><![CDATA[Most XML standards supply schemas to validate XML documents. However, these schemas are often a direct conversion from a DTD. This introduces an unnecessary ambiguity for the root element. This might be harmful and is easily avoided.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=33&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>
<p style="margin-top:0;margin-bottom:1px;">Once upon a time XML was born from SGML. And along with its birth came DTDs to define the document structure. Life was good. Everybody used to writing DTDs for SGML could keep doing so. And so they did…</p>
<p style="margin-top:0;margin-bottom:1px;">But what happened? Newer and shinier methods for describing XML structures came along. W3C Schemas, Relax NG and others saw the light. Suddenly things that were impossible to do with DTDs became feasible: data typing, design modularization and many, many more. Wow! Suddenly you could <i>really</i> be strict about your document structure.</p>
<p style="margin-top:0;margin-bottom:1px;">And so what happened in the ivory towers from which the gods send us their XML standards for us mere mortals to use? Where the standards accompanied by schemas in addition to the traditional DTDs? Yes, they were! Hurrah, a step forward. Now we can really and truly verify our documents. </p>
<p style="margin-top:0;margin-bottom:1px;">But look closely. Are this schemas? Technically… yes. However they look an awful lot like DTDs. If I am not mistaken most of the DTDs are simply <i>converted</i> into schemas.</p>
<p style="margin-top:0;margin-bottom:1px;">All right, so what?<span id="more-33"></span> The standard developers (at least, most of them) seem to have chosen to keep on using DTDs. As a gesture to us humans they add schemas, but only schemas converted from their DTDs. No data typing, no modularization, nothing but elements and attributes.</p>
<p style="margin-top:0;margin-bottom:1px;">And so we stay in the dark ages of XML design and miss all the opportunities to be more strict. But what&#8217;s even worse, it introduces an ambiguity: You can now validate documents with a completely different root element than intended… </p>
<h4>Multiple root elements?</h4>
<p style="margin-top:0;margin-bottom:1px;">As an illustrative example, let&#8217;s assume we want to define the structure for this very complex XML document:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;Names&gt;
   &lt;Name&gt;Erik&lt;/Name&gt;
   &lt;Name&gt;John&lt;/Name&gt;
   &lt;!-- etc. --&gt;
&lt;/Names&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">A DTD for this could look like this:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;!ELEMENT Names ((Name+))&gt;
&lt;!ELEMENT Name (#PCDATA)&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">This DTD defines that <code style="font-size:1.2em;color:#008099;">&lt;Names&gt;</code> is the root element because it is not part of any other element&#8217;s definition. But if we convert this DTD directly into a schema (I use the build-in XML Spy convertor) something like this appears:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&gt;
   &lt;xs:element name="Names"&gt;
       &lt;xs:complexType&gt;
           &lt;xs:sequence&gt;
               &lt;xs:choice&gt;
                   &lt;xs:element ref="Name" maxOccurs="unbounded"/&gt;
               &lt;/xs:choice&gt;
           &lt;/xs:sequence&gt;
       &lt;/xs:complexType&gt;
   &lt;/xs:element&gt;
   &lt;xs:element name="Name"&gt;
       &lt;xs:complexType mixed="true"/&gt;
   &lt;/xs:element&gt;
&lt;/xs:schema&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">So, what&#8217;s wrong with this: The root element has become ambiguous! For instance, this is a perfectly valid XML document according to our brand new schema:</p>
<p>
<pre style="border:solid 1px blue;font-size:1.3px em;color:blue;background:#FFFFB3;margin:10px;padding:10px;">&lt;Name&gt;Erik&lt;/Name&gt;
</pre>
<p>
<p style="margin-top:0;margin-bottom:1px;">Not exactly what we would like, is it?</p>
<h4>But is it a problem?</h4>
<p style="margin-top:0;margin-bottom:1px;">Yes. Definitely. Period.</p>
<p style="margin-top:0;margin-bottom:1px;">DTDs were introduced to be able define the structure of our XML documents unambiguous. Schemas were introduced to make this even better. But now, by actually using schemas, we make it worse.</p>
<p style="margin-top:0;margin-bottom:1px;">It could be the cause of all kinds of subtle and not so subtle errors when invalid XML, which a validator accepts undeserved, passes through systems. It might open backdoors for hackers because invalid data is accepted without raising alarms. And you could spent many unproductive hours debugging something that might have been detected very easily.</p>
<p>
<p style="margin-top:0;margin-bottom:1px;">Oh, by the way: The schema feature to have more than one root elements is not a bug as such. There are situations you actually need it. For instance when you on purpose want to have a schema that allows multiple root elements. Or when you define a schema with elements for use inside another namespace. </p>
<h4>What to do about it?</h4>
<p style="margin-top:0;margin-bottom:1px;">Do not blindly convert your DTDs into schemas and think you&#8217;re finished.</p>
<p style="margin-top:0;margin-bottom:1px;">Create your schemas (or adapt the conversions) in such a way that only one root element is possible (unless of course you mean something else on purpose).</p>
<p style="margin-top:0;margin-bottom:1px;">And to get the best results: Use the features a schema language possesses to define the structure of your XML as tight as possible. And that is a lot more tight than a DTD!</p>
<p> </p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/xatapult.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/xatapult.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/xatapult.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/xatapult.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/xatapult.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/xatapult.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/xatapult.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/xatapult.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=xatapult.wordpress.com&amp;blog=9162738&amp;post=33&amp;subd=xatapult&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://xatapult.wordpress.com/2009/09/07/standarddtdsschemas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/55a98e2701203f29b4f4ab3ce731d4d8?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">xatapult</media:title>
		</media:content>
	</item>
	</channel>
</rss>
