<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5048327124946889578</id><updated>2012-01-28T13:48:10.769+05:30</updated><category term='linux'/><category term='xml'/><category term='xerces'/><category term='xml-schema'/><category term='theory'/><category term='dom'/><category term='xquery'/><category term='java'/><category term='oo'/><category term='web'/><category term='dtd'/><category term='xpath'/><category term='uml'/><category term='mozilla'/><category term='xslt'/><category term='eclipse'/><category term='xalan'/><category term='grid'/><title type='text'>Mukul Gandhi</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default?start-index=101&amp;max-results=100'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>108</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4272136034544649574</id><published>2012-01-26T15:39:00.001+05:30</published><updated>2012-01-28T13:48:10.886+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Using XSD 1.1 assertions on complexType mixed contents</title><content type='html'>There were some interesting ;) thoughts coming to my mind lately, and not surprisingly again related to &lt;a href="http://www.w3.org/XML/Schema" target="_blank"&gt;XSD&lt;/a&gt;. I was playing with XSD 1.1 assertions once again to try to constrain an XSD complexType{mixed} content model and I'm sharing some of my findings ... (I guess, I hadn't written about this particular topic on this blog before or on any other forum. If you find any duplicacy of information in this post with any information I might have written elsewhere, kindly ignore the earlier things I might have written). I come to the topic now.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;What is XSD mixed content (you may ignore reading this, if you already know about this)?&lt;/b&gt;&lt;br /&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;I believe, this isn't really an XSD only topic. It is something which is present in plain XML (there can be a good old well-formed XML document, which might have "mixed" content and needn't be validated at all -- i.e in a schema free XML environment), but XSD allows to report such an XML instance document as 'valid' (more importantly, XSD would report a "mixed" content model XML instance as 'invalid' if validated by an "element only" content model specified by an XSD complexType definition) and also to constrain XML mixed contents in certain ways (particularly with XSD 1.1 in some new ways, which I'll try to talk about further below).&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;Example of "element only" (content of element "X" here) XML content model [X1]:&lt;br /&gt;&lt;br /&gt;&amp;lt;X&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;Y/&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;Z/&amp;gt;&lt;br /&gt;&amp;lt;/X&amp;gt;&lt;/pre&gt;&lt;pre&gt;Example of "mixed content" (content of element "X" here) XML content model [X2]: &lt;br /&gt;&lt;br /&gt;&amp;lt;X&amp;gt;&lt;br /&gt;&amp;nbsp; abc&lt;br /&gt;&amp;nbsp; &amp;lt;Y/&amp;gt;&lt;br /&gt;&amp;nbsp; 123&lt;br /&gt;&amp;nbsp; &amp;lt;Z/&amp;gt;&lt;br /&gt;&amp;nbsp; 654&lt;br /&gt;&amp;lt;/X&amp;gt; &lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;Therefore, "mixed content" allows "non whitespaced" text nodes as siblings of element nodes.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;XSD 1.0 schema definition that allows "mixed" content [XS1]:&lt;/b&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="X"&amp;gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:complexType &lt;span style="background-color: #ffd966;"&gt;mixed="true"&lt;/span&gt;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="Y"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="Z"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;lt;/xs:schema&amp;gt;&lt;/pre&gt;&lt;br /&gt;This schema (XS1) would report the XML document "X2" above as 'valid' (since that instance document has "mixed" content, and this schema allows "mixed" content via a property "mixed = 'true'" on a complexType definition).&lt;br /&gt;&lt;br /&gt;But in the schema document "XS1" above, if we remove the property specifier "mixed = 'true'" or set the value of attribute "mixed" as 'false' (which is also the default value of this attribute), then such a modified schema would report the XML instance document "X2" above as 'invalid' (but the XML document "X1" above would be reported as 'valid' -- since it doesn't has "mixed" content).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;New capabilities provided by XSD 1.1 to constrain XML "mixed" content further:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Following is a list of new features supported by XSD 1.1 for XML "mixed" contents, that currently come to my mind,&lt;br /&gt;&lt;br /&gt;a)&lt;br /&gt;&lt;br /&gt;XSD 1.1 schema "XS2":&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="X"&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;lt;xs:complexType mixed="true"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="Y"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="Z"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:sequence&amp;gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:assert test="deep-equal(text()[matches(.,'\w')]/normalize-space(.), ('abc','123','654'))"/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;lt;/xs:schema&amp;gt;&lt;/pre&gt;The &amp;lt;assert&amp;gt; element in this schema (XS2) constrains the mixed content in XML instance document to be a list (with order of list items been significant) of only few specified values. The assertion is written only to illustrate the technical capabilities of an assertion here, but not with any application in mind.&lt;br /&gt;Following are few of other things, which XSD 1.1 assertions could achieve in an XML "mixed" content model's context:&lt;br /&gt;&lt;br /&gt;b)&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:assert test="((text()[matches(.,'\w')]/normalize-space(.))[2] castable as xs:integer)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; ((text()[matches(.,'\w')]/normalize-space(.))[3] castable as xs:integer)"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;This assertion constrains specific items of an XML "mixed" content model list to be of a specified XSD schema type -- here the 2nd and 3rd items of the list need to be typed as xs:integer, whereas the first item is "untyped".&lt;br /&gt;&lt;br /&gt;c)&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:assert test="count((text()[matches(.,'\w')]/normalize-space(.))[. castable as xs:integer])&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; =&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(text()[matches(.,'\w')]/normalize-space(.))"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;This assertion constrains all items of the XML "mixed" content model list to be of the same type (xs:integer in this case) -- this uses a well defined pattern "count of xs:integer items is equal to the count of all the items".&lt;br /&gt;&lt;br /&gt;d)&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:assert test="every $x in text()[matches(.,'\w')][position() gt 1]&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; satisfies &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; (number(normalize-space($x)) gt number($x/preceding-sibling::text()[matches(.,'\w')][1]))"/&amp;gt;&lt;/pre&gt;&lt;br /&gt;This assertion constrains the list of XML "mixed" content model to be in ascending numeric order (assuming that all items in the list are numeric. Though it should be possible to specify a numeric order on a heterogeneously typed list, and specify numeric order only for numeric list items).&lt;br /&gt;&lt;br /&gt;Summary: XSD 1.0 allowed an "untyped" XML mixed content, that was uniformly available anywhere within the scope of an XML element that was validated by an XSD complexType. No further constraints on "mixed" content were possible in an XSD 1.0 environment. XSD 1.1 allows some new ways to constrain XML "mixed" content further (some of these capabilities were illustrated in examples above). To my opinion, the likely benefits of constraining XML "mixed" content in some of the ways as illustrated above, is to allow the XML document authors to model certain semantic content in "mixed" content scope and make this knowledge available to the XML applications. All examples above were tested with Apache Xerces (I hope that these examples would also be compliant with other XSD validators, notably Saxon currently which also supports XSD 1.1).&lt;br /&gt;&lt;br /&gt;I hope that this information was useful.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4272136034544649574?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4272136034544649574/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4272136034544649574' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4272136034544649574'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4272136034544649574'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2012/01/using-xsd-11-assertions-on-complextype.html' title='Using XSD 1.1 assertions on complexType mixed contents'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5741863864058465220</id><published>2011-08-23T19:57:00.034+05:30</published><updated>2011-11-11T21:37:24.349+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><title type='text'>XPath 2.0 and XSD schemas : sharing experiences</title><content type='html'>I was just playing with &lt;a href="http://www.w3.org/TR/xpath20/"&gt;XPath 2.0&lt;/a&gt; and thought of sharing my observations, about a specific use case.&lt;br /&gt;&lt;br /&gt;We start with the following &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; schema document,&lt;br /&gt;&lt;pre style="color: #0b5394;"&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;          &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element name="a" type="xs:integer"/&amp;gt;&lt;br /&gt;          &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:attribute name="att1" type="xs:boolean"/&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&amp;nbsp;&lt;/pre&gt;&lt;pre style="color: #0b5394;"&gt;&amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This schema intends to validate an XML instance document like following,&lt;br /&gt;&lt;pre style="color: #0b5394;"&gt;&amp;lt;X att1="0"&amp;gt;&lt;br /&gt;  &amp;lt;a&amp;gt;100&amp;lt;/a&amp;gt;&lt;br /&gt;&amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I wrote an XPath (2.0) expression like following [1],&lt;br /&gt;&lt;br /&gt;&lt;span style="color: #b45f06;"&gt;/X[if (@att1) then true() else false()]/a/text()&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;      AND ran this after enabling validation of the input document.&lt;br /&gt;&lt;br /&gt;I though that this would not return any result (i.e an empty sequence).&lt;br /&gt;&lt;br /&gt;But the XPath expression above ([1]) returns the result "100". At first thought, I was little amazed by this result. I thought, that since attribute "att1" was declared with type xs:boolean in the schema, the "if condition" should return 'false' in this case. But that's not the correct interpretation of the XPath expression written above ([1]). Following is a little more explanation about this.&lt;br /&gt;&lt;br /&gt;The reference @att1 in the XPath expression above (i.e if (@att1) ..) is a node reference (an attribute node) and is not a boolean value (which I thought initially, and I was wrong -- I incorrectly thought, that atomization of the expression @att1 would take place in this case; more about this below).&lt;br /&gt;&lt;br /&gt;The XPath 2.0 spec says, that if the first item in the sequence is a non null node, then effective boolean value of such a sequence is 'true' (this interpretation is unaffected by the fact, if the input XML document was validated or not with the XSD schema). And in the expression like above (i.e if (@att1) ..), the effective boolean value of the sequence {@att1} is used to determine IF the "if condition" returns 'true' or not (in this case, this sequence has one item [which is also the first item of this sequence] which is an attribute node whose name is "att1", which makes the effective boolean value as 'true' -- and hence the XPath predicate evaluates to 'true'). I think this explains, why the "if condition" {if (@att1)} would return true for the above XML instance document (even if it was validated by the schema given above, and the XPath 2.0 expression above [1] was run in a schema aware mode).&lt;br /&gt;&lt;br /&gt;To write the XPath expression correctly, as I wanted (i.e the expression of the "if condition" should return 'true' if the instance document had value true/1 for the attribute, and 'false' otherwise AND an XSD validation of instance document took place prior to the evaluation of the XPath expression), the XPath expression would need to be modified to either of the following styles [2],&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #b45f06;"&gt;/X[if (data(@att1)) then true() else false()]/a/text()&lt;/div&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #b45f06;"&gt;/X[if (@att1 = true()) then true() else false()]/a/text()&lt;/div&gt;&lt;br /&gt;To understand why the expressions given above ([2]) work correctly, one needs to understand the XPath 2.0 "data" function (for the first correct variant above, [2] -- this returns the typed value of the argument of the "data" function) and the process of atomization (for the second correct variant above, [2] -- in this case the attribute node "att1" is atomized to return a sequence of kind {xs:boolean}) as described by the XPath 2.0 spec.&lt;br /&gt;&lt;br /&gt;That's all about this. I hope that my experience with this may be helpful to someone (to understand this, one just has to know the XPath [2.0] spec correctly, and how it interacts with XSD schemas!).&lt;br /&gt;&lt;br /&gt;Thanks for reading this post.&lt;br /&gt;&lt;br /&gt;@2011-11-11: updated in place, to correct few factual errors.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5741863864058465220?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5741863864058465220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5741863864058465220' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5741863864058465220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5741863864058465220'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2011/08/xpath-20-and-xsd-schemas-sharing.html' title='XPath 2.0 and XSD schemas : sharing experiences'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2203854426083939600</id><published>2011-07-26T19:26:00.004+05:30</published><updated>2011-07-31T07:37:16.893+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>[revisiting] Xerces-J XSModel serializer</title><content type='html'>I started playing a bit with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; XSSerializer utility (it's actually a sample within Xerces-J and was introduced in Xerces-J 2.10.0 -- the version in SVN is slightly better and will be released with a future Xerces release; and it serializes an in-memory Xerces XSModel instance into a lexical &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; syntax), and thought of writing something about it's features.&lt;br /&gt;&lt;br /&gt;XSModel serializer has following two important (and currently the only ones) serialization features/options:&lt;br /&gt;1. Selecting the XSD language version, the XSModel serializer should work with. By default this is XSD 1.0, but it can be set to XSD 1.1 via the following command line parameter, {-version 1.1}. There are very few XSD 1.1 features that the XSModel serializer currently supports. We'll try to add more XSD 1.1 features in future to the XSModel serializer. But the XSD 1.0 support with Xerces's XSModel serializer is fairly complete. &lt;br /&gt;2. The XSD language prefix during serialization output can be configured with the option, {-prefix &amp;lt;prefix-value&amp;gt;}. For e.g "-prefix xsd". If this option is not specified, the prefix "xs" is generated as default during XSModel instance serialization.&lt;br /&gt;&lt;br /&gt;I've had few interesting observations while using the Xerces XSSerializer (illustrated with small examples below),&lt;br /&gt;&lt;br /&gt;1. I supplied the following XSD document (only the element declaration is shown, since this is the focus of this point) to the XSModel serializer,&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:element name="E1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;xs:list&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;           &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;              &amp;lt;xs:minLength value="5"/&amp;gt;&lt;br /&gt;           &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;/xs:list&amp;gt;&lt;br /&gt;   &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and the XSModel serializer echoed this element instance (the XSModel serializer converted the lexical schema into XSModel instance, and then serialized the XSModel again to lexical XSD syntax) to following,&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:element name="E1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;xs:list&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;            &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;               &amp;lt;xs:whiteSpace value="preserve"/&amp;gt;&lt;br /&gt;               &amp;lt;xs:minLength value="5"/&amp;gt;&lt;br /&gt;            &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;/xs:list&amp;gt;&lt;br /&gt;   &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The interesting thing I notice in this example is, the generation of the built in facet "whiteSpace" for the XSD type xs:string.&lt;br /&gt;&lt;br /&gt;2. Serializing the following XSD element,&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:element name="E1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;xs:list&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;            &amp;lt;xs:restriction base="xs:integer"&amp;gt;&lt;br /&gt;               &amp;lt;xs:minInclusive value="5"/&amp;gt;&lt;br /&gt;            &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;/xs:list&amp;gt;&lt;br /&gt;   &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;produces the following round-trip output with the XSModel serializer,&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:element name="E1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;xs:list&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;            &amp;lt;xs:restriction base="xs:integer"&amp;gt;&lt;br /&gt;               &amp;lt;xs:whiteSpace value="collapse"/&amp;gt;&lt;br /&gt;               &amp;lt;xs:fractionDigits value="0"/&amp;gt;&lt;br /&gt;               &amp;lt;xs:minInclusive value="5"/&amp;gt;&lt;br /&gt;               &amp;lt;xs:pattern value="[\-+]?[0-9]+"/&amp;gt;&lt;br /&gt;            &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;/xs:list&amp;gt;&lt;br /&gt;   &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;this shows the built in facets for the XSD type xs:integer ("whiteSpace", "fractionDigits" and others).&lt;br /&gt;&lt;br /&gt;I personally like this feature of XSModel serializer, that it is able to generate certain hidden properties of XML Schema components, which the schema authors normally don't specify while writing the schema documents for applications.&lt;br /&gt;&lt;br /&gt;3. I provided the following XSD Schema fragment to XSModel serializer (a complexType referring to a model group),&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:element name="E1"&amp;gt;&lt;br /&gt;  &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;xs:group ref="gp1"/&amp;gt;&lt;br /&gt;  &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;&amp;lt;xs:group name="gp1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="x" type="xs:string"/&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="y" type="xs:string"/&amp;gt;&lt;br /&gt;   &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;&amp;lt;/xs:group&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and the XSModel serializer generated the following round-trip serialization result,&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:element name="E1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;      &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="x" type="xs:string"/&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="y" type="xs:string"/&amp;gt;&lt;br /&gt;      &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;   &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xs:group name="gp1"&amp;gt;&lt;br /&gt;   &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="x" type="xs:string"/&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="y" type="xs:string"/&amp;gt;&lt;br /&gt;   &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;&amp;lt;/xs:group&amp;gt;&lt;br /&gt;&lt;/pre&gt;The global "model group" is serialized as expected. But the complexType within the element declaration was serialized with it's element declarations expanded. The lexical group reference is not present in the serialized output.&lt;br /&gt;&lt;br /&gt;At first this may look odd (i.e the absence of the model group reference) in the serialized output. But the fact is, that Xerces XSModel instance in it's complete compiled form, doesn't know whether a group particle (in this case xs:sequence) comes from a group reference. And I had to live with this XSModel serialization characteristic. But the serialized schema output in this example is equivalent to the original schema document (which was supplied to the XSModel serializer) from validation perspective (but the global group definition in the output in this case is redundant from validation perspective, and it's just a characteristic of the XSModel serializer currently).&lt;br /&gt;&lt;br /&gt;That's all I have to say now. Thanks for reading this post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2203854426083939600?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2203854426083939600/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2203854426083939600' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2203854426083939600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2203854426083939600'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2011/07/revisiting-xerces-j-xsmodel-serializer.html' title='[revisiting] Xerces-J XSModel serializer'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6083450842466167773</id><published>2011-06-04T06:59:00.005+05:30</published><updated>2011-06-26T19:15:24.160+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Dealing with multiple roots within an XML Schema</title><content type='html'>I've been thinking on this problem for a while, and have collected some opinions, which I'm presenting here.&lt;br /&gt;&lt;br /&gt;We'll be working with the following XML Schema documents:&lt;br /&gt;&lt;br /&gt;a.xsd  [1]&lt;br /&gt;&lt;pre style="color: #e06666;"&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="x" type="xs:string"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="y" type="xs:string"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="z"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;          &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element ref="x"/&amp;gt;&lt;br /&gt;             &amp;lt;xs:element ref="y"/&amp;gt;&lt;br /&gt;          &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;b.xsd  [2]&lt;br /&gt;&lt;pre style="color: #e06666;"&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:include schemaLocation="c.xsd"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="z"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;          &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element ref="x"/&amp;gt;&lt;br /&gt;             &amp;lt;xs:element ref="y"/&amp;gt;&lt;br /&gt;          &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;c.xsd  [3]&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #e06666;"&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="x" type="xs:string"/&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="y" type="xs:string"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xs:schema&amp;gt;&lt;/span&gt;&lt;/pre&gt;The schema documents [1] and [2] are equivalent for the purpose of validating an XML instance document (it's just that the schema document b.xsd includes c.xsd).&lt;br /&gt;&lt;br /&gt;Our application requires the following XML document to be successfully validated, by the schemas [1] or [2] above:&lt;br /&gt;&lt;br /&gt;z.xml  [4]&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #e06666;"&gt;&amp;lt;z&amp;gt;&lt;br /&gt;   &amp;lt;x&amp;gt;hello&amp;lt;/x&amp;gt;&lt;br /&gt;   &amp;lt;y&amp;gt;world&amp;lt;/y&amp;gt;&lt;br /&gt;&amp;lt;/z&amp;gt;&lt;/span&gt;&lt;/pre&gt;All of this is just fine, and XML document [4] get's successfully validated by the schemas [1] or [2] above.&lt;br /&gt;&lt;br /&gt;But the above schema design (either [1] or [2]), may present following problems sometimes:&lt;br /&gt;&lt;br /&gt;The side effect of schema documents [1] or [2] is to also successfully validate the following XML documents,&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #e06666;"&gt;&amp;lt;x&amp;gt;...&amp;lt;/x&amp;gt;&lt;/div&gt;&lt;br /&gt;OR&lt;br /&gt;&lt;br /&gt;&lt;div style="color: #e06666;"&gt;&amp;lt;y&amp;gt;...&amp;lt;/y&amp;gt;&lt;/div&gt;Since elements "x" and "y" are also valid roots defined in the schema (due to the global declarations of elements "x" and "y" in the schema). But the purpose of defining elements "x" and "y" in the schema, is to include them by reference else where in the schema document (as in element declaration "z" in schemas [1] or [2]).&lt;br /&gt;&lt;br /&gt;This kind of schema design is sometimes necessary, for the reasons of modularity (for e.g using one declaration at multiple places) and re-usability (for e.g. by including a foreign schema in our own schema) -- this design can be more beneficial, if the complexity of the schema (for e.g with more schema components, and more &amp; deep nesting of schema components) is more.&lt;br /&gt;&lt;br /&gt;So how do we live with following design trade-off,&lt;br /&gt;i.e having schema like [1] or [2] above (which gives us benefits of modularity and re-usability) and also a side effect of these schema documents validating multiple root elements (which risks an application to accept invalid XML documents -- in this example, the roots "x" and "y" are invalid for the application, while the root "z" is valid).&lt;br /&gt;&lt;br /&gt;In this use case, if we desire that the application must reject XML documents with roots "x" or "y" but should accept documents with root "z", then to my opinion this problem cannot be solved completely with XML Schema language (there's no way currently in the XML Schema language, to forbid validating the top level XML element in instance document, with a global schema element declaration).&lt;br /&gt;&lt;br /&gt;Solving this problem would require a little bit of non schema solution (for e.g a SAX java add-on along with schema validation).&lt;br /&gt;&lt;br /&gt;Here's a sketch of a java SAX application which can be and-ed with the XML Schema validation (using schemas above), to achieve the desired overall XML validation effect (i.e successful validation for the root element "z" and prohibiting the XML roots "x" and "y"),&lt;br /&gt;&lt;br /&gt;(java imports are omitted to keep the text short)&lt;br /&gt;&lt;pre style="color: #b45f06;"&gt;class SAXUtil extends DefaultHandler {&lt;br /&gt;&lt;br /&gt;     String[] excludedElems = new String[] {"x", "y"};&lt;br /&gt;&lt;br /&gt;     private boolean isRootElemOK(String docUri) {  &lt;br /&gt;        boolean rootElemOk = true;&lt;br /&gt;  &lt;br /&gt;        try {&lt;br /&gt;           SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();&lt;br /&gt;           saxParserFactory.setNamespaceAware(true);&lt;br /&gt;           SAXParser saxParser = saxParserFactory.newSAXParser();&lt;br /&gt;           saxParser.parse(docUri, this);&lt;br /&gt;        }&lt;br /&gt;        catch(SAXException ex) {&lt;br /&gt;           if (ex instanceof RootElementSAXException) {&lt;br /&gt;              RootElementSAXException expObj = (RootElementSAXException) ex;&lt;br /&gt;              if ("100".equals(expObj.getErrCode())) {&lt;br /&gt;                 rootElemOk = false;  &lt;br /&gt;              }&lt;br /&gt;           }&lt;br /&gt;        }&lt;br /&gt;  &lt;br /&gt;        return rootElemOk;  &lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {&lt;br /&gt;        if (!isElementAllowed(localName)) {&lt;br /&gt;           throw new RootElementSAXException("100"); &lt;br /&gt;        }&lt;br /&gt;        throw new RootElementSAXException("101");&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     private boolean isElementAllowed(String localName) {    &lt;br /&gt;        boolean elemAllowed = true;       &lt;br /&gt;        for (int elemIdx = 0; elemIdx &amp;lt; excludedElems.length; elemIdx++) {&lt;br /&gt;           if (localName.equals(excludedElems[elemIdx])) {&lt;br /&gt;              elemAllowed = false;&lt;br /&gt;              break;&lt;br /&gt;           }&lt;br /&gt;        }       &lt;br /&gt;        return elemAllowed;       &lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;     class RootElementSAXException extends SAXException {&lt;br /&gt;        String errorCode;&lt;br /&gt;  &lt;br /&gt;        public RootElementSAXException(String errorCode) {&lt;br /&gt;           this.errorCode = errorCode;&lt;br /&gt;        }&lt;br /&gt;  &lt;br /&gt;        public String getErrCode() {&lt;br /&gt;           return errorCode;&lt;br /&gt;        }&lt;br /&gt;     }&lt;br /&gt;&lt;br /&gt;} // class SAXUtil&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Following is an algorithmic summary of the above java validation add-on,&lt;br /&gt;&lt;br /&gt;1) A SAX parser is instantiated and parsing is invoked/triggered with the parse() method.&lt;br /&gt;&lt;br /&gt;2) The SAX parser cannot go beyond parsing the root element -- the algorithm is intentionally designed in this way (since the SAX "startElement" callback method would always throws an exception [user defined exception, RootElementSAXException], upon encountering the top most element). The constructor parameter to the exception ("100" or "101" in this case) RootElementSAXException determines, whether the top most element was allowed or not (which is determined by an element name forbidden-list "excludedElems", defined in the above java class).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Notes:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;1) To terminate the SAX parsing prior to completing parsing the whole of XML document, a SAXException can be thrown from the SAX call back methods. A custom exception class (like RootElementSAXException in the above example) is desirable, to distinguish our application designed exception from the built in SAXException events.&lt;br /&gt;&lt;br /&gt;2) It's recommended to use SAX API for this use case, since it'll be much more efficient than for e.g using DOM APIs, which would load the whole of XML document in memory (which doesn't look a sensible approach to me, for just knowing the name of top most element of XML document).&lt;br /&gt;&lt;br /&gt;3) The exclude element name list can be externalized from the java application, to make the above program reusable for any kind of XML documents.&lt;br /&gt;&lt;br /&gt;4) We may use something like the java JAXP validation APIs, to help achieve the "and" of the two validation steps (i.e, schema validation and the SAX application step) described here, if we want to integrate this approach in a java application.&lt;br /&gt;&lt;br /&gt;5) The java code snippet presented above can be made XML namespace aware (i.e if the XML elements are in namespace), by considering the namespace name parameter in SAX callback methods (for e.g the method parameter "String uri", in the startElement callback method).&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;2011-06-26:&lt;/i&gt;&lt;br /&gt;The explanation given by me in this blog post originally, seems to convey that multiple global element declarations in XML Schema documents are allowable by the XML Schema language, and this is inherently a bad/wrong design present within the XML Schema language. One of the solution to prohibit certain XML elements to be global in an XML instance document, was presented earlier in this blog post (using an additional restricted SAX parsing step in an application).&lt;br /&gt;&lt;br /&gt;All this is fine. But I wanted to follow up on my thoughts written earlier in this post, arguing now, that multiple global element declarations allowable in XML Schema language is not a bad/wrong design present in XML Schema language. One of the features of XML Schema language, which requires multiple global element declarations is XML Schema "substitution groups" (i.e one element substituting for another) -- and "substitution groups" is a core and important concept within XML Schema language.&lt;br /&gt;&lt;br /&gt;Of-course, if not working with XML Schema "substitution groups" or otherwise, one could use the SAX add-on technique I presented earlier to prohibit certain global element declarations to validate the XML instance root element, if that suits someones application design.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6083450842466167773?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6083450842466167773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6083450842466167773' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6083450842466167773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6083450842466167773'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2011/06/dealing-with-multiple-roots-within-xml.html' title='Dealing with multiple roots within an XML Schema'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8085016399665897966</id><published>2011-04-30T12:33:00.002+05:30</published><updated>2011-05-06T18:48:50.143+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XML Schema: facets constraining the cardinality of simpleType-&gt;list</title><content type='html'>I thought I should write a little clarification of a point I mentioned in my blog post, &lt;a href="http://mukulgandhi.blogspot.com/2010/10/xsd-11-xml-schema-design-approaches.html"&gt;http://mukulgandhi.blogspot.com/2010/10/xsd-11-xml-schema-design-approaches.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I seem to have suggested in the above cited post, that XML Schema 1.1 assertions are probably necessary to impose restrictions on cardinality of an XML Schema simpleType list instance. But this fact doesn't appear to be true, after I realized this reading the XML Schema spec lately; which allows the following constraining facets on XML Schema simpleType's with variety list:&lt;br /&gt;[1]&lt;br /&gt;&amp;lt;xs:length ../&amp;gt;&lt;br /&gt;&amp;lt;xs:minLength ../&amp;gt;&lt;br /&gt;&amp;lt;xs:maxLength ../&amp;gt;&lt;br /&gt;&lt;br /&gt;(ref, &lt;a href="http://www.w3.org/TR/xmlschema11-2/#defn-coss"&gt;http://www.w3.org/TR/xmlschema11-2/#defn-coss&lt;/a&gt; which says, "If {variety} is list, then the applicable facets are assertions, &lt;b&gt;length&lt;/b&gt;, &lt;b&gt;minLength&lt;/b&gt;, &lt;b&gt;maxLength&lt;/b&gt;, pattern, enumeration, and whiteSpace")&lt;br /&gt;&lt;br /&gt;These constraining facets [1], on simpleType with variety list were available in XML Schema 1.0 too.&lt;br /&gt;&lt;br /&gt;These facets [1] may serve the design purpose (and should probably be even efficient than using assertions, since assertions require compiling the XPath expressions in their "test" attribute's, and to build quite a bit of context information for XPath expression evaluation) I had mentioned in the above cited post.&lt;br /&gt;&lt;br /&gt;Also to mention, that an assertion facet for simpleType with variety list, could be found useful for other purposes (i.e they are not without purpose!), for example as follows:&lt;br /&gt;&lt;br /&gt;&amp;lt;xs:assertion test="count($value) mod 2 = 0"/&amp;gt;&lt;br /&gt;&lt;br /&gt;(the list instance must have even number of items)&lt;br /&gt;&lt;br /&gt;Thanks for reading this post!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8085016399665897966?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8085016399665897966/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8085016399665897966' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8085016399665897966'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8085016399665897966'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2011/04/xml-schema-facets-constraining.html' title='XML Schema: facets constraining the cardinality of simpleType-&gt;list'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1637610443693616759</id><published>2011-01-01T09:13:00.002+05:30</published><updated>2011-04-26T06:19:54.859+05:30</updated><title type='text'>Happy New Year 2011</title><content type='html'>I wish readers of this blog a very Happy New Year 2011.&lt;br /&gt;&lt;br /&gt;My new year resolutions are to have more interactions with the online community, particularly with folks at &lt;a href="http://www.w3.org/standards/xml/"&gt;XML&lt;/a&gt;, &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt;, &lt;a href="http://www.w3.org/Style/XSL/"&gt;XSL&lt;/a&gt; and &lt;a href="http://www.w3.org/XML/Query/"&gt;XQuery&lt;/a&gt; forums. And I do wish to see W3C-standards progress on XML Schema 1.1, XPath 3.0, XSLT 3.0 and XQuery 3.0 languages (these are great new XML languages which I'm following-up with recently). I'm also reading through the discussions at the newly setup &lt;a href="http://lists.w3.org/Archives/Public/public-html-xml/2010Dec/0028.html"&gt;HTML-XML convergence task force&lt;/a&gt; (I hope we'll see few nice decisions emerging there)!&lt;br /&gt;&lt;br /&gt;And needless to mention, I'm looking to work more closely with &lt;a href="http://www.eclipse.org/"&gt;Eclipse&lt;/a&gt; community.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1637610443693616759?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1637610443693616759/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1637610443693616759' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1637610443693616759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1637610443693616759'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2011/01/happy-new-year-2011.html' title='Happy New Year 2011'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6445061921880997223</id><published>2010-12-28T17:30:00.001+05:30</published><updated>2010-12-28T17:40:18.437+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Schema based XML compare</title><content type='html'>David A. Lee (producer of &lt;a href="http://www.xmlsh.org"&gt;XMLSH&lt;/a&gt; -- A command line shell for XML) raised an interesting discussion a while ago on &lt;a href="http://www.xml.org/xml-dev"&gt;XML-DEV&lt;/a&gt; mailing list, about how to do XML Schema aware XML document comparison. The whole of this discussion thread can be &lt;a href="http://lists.xml.org/archives/xml-dev/201012/msg00777.html"&gt;read here&lt;/a&gt;. &lt;a href="http://saxonica.blogharbor.com/blog"&gt;Michael Kay&lt;/a&gt; suggested to use the XPath 2.0 function &lt;a href="http://www.w3.org/TR/xpath-functions/#func-deep-equal"&gt;deep-equal&lt;/a&gt; (where the input document trees need to be validated by a schema -- to enable type-aware comparison, before doing a comparison by this function) for this kind of use case. Following Michael's idea I was playing with this concept using IBM's XPath 2.0 engine (which is XML Schema aware and is a component of &lt;a href="http://www-01.ibm.com/software/webservers/appserv/was/featurepacks/xml/"&gt;WebSphere Application Server feature pack for XML&lt;/a&gt;). For the interest of readers, here's a minimal Java program illustrating this program design.&lt;br /&gt;&lt;pre&gt;package com.ibm.xpath2;&lt;br /&gt;&lt;br /&gt;import javax.xml.namespace.QName;&lt;br /&gt;import javax.xml.transform.stream.StreamSource;&lt;br /&gt;&lt;br /&gt;import com.ibm.xml.xapi.XDynamicContext;&lt;br /&gt;import com.ibm.xml.xapi.XFactory;&lt;br /&gt;import com.ibm.xml.xapi.XPathExecutable;&lt;br /&gt;import com.ibm.xml.xapi.XSequenceCursor;&lt;br /&gt;import com.ibm.xml.xapi.XSequenceType;&lt;br /&gt;import com.ibm.xml.xapi.XStaticContext;&lt;br /&gt;&lt;br /&gt;public class XMLCompare {&lt;br /&gt;&lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        String dataDir = System.getProperty("dataDir.path");&lt;br /&gt;  &lt;br /&gt;        XFactory factory = XFactory.newInstance();&lt;br /&gt;        factory.setValidating(XFactory.FULL_VALIDATION);&lt;br /&gt;        factory.registerSchema(new StreamSource(dataDir + "/test.xsd"));&lt;br /&gt;        &lt;br /&gt;        XStaticContext staticContext = factory.newStaticContext();&lt;br /&gt;        staticContext.declareVariable(new QName("doc1"), factory.getSequenceTypeFactory().                      documentNode(XSequenceType.OccurrenceIndicator.ONE));&lt;br /&gt;        staticContext.declareVariable(new QName("doc2"), factory.getSequenceTypeFactory().                                      documentNode(XSequenceType.OccurrenceIndicator.ONE));&lt;br /&gt;        XDynamicContext dynamicContext = factory.newDynamicContext();&lt;br /&gt;        dynamicContext.bind(new QName("doc1"), new StreamSource(dataDir + "/test1.xml"));&lt;br /&gt;        dynamicContext.bind(new QName("doc2"), new StreamSource(dataDir + "/test2.xml"));&lt;br /&gt;                &lt;br /&gt;        XPathExecutable executable = factory.prepareXPath("deep-equal($doc1, $doc2)", staticContext);&lt;br /&gt;        XSequenceCursor result = executable.execute(dynamicContext);&lt;br /&gt;        if (result.exportAsList().get(0).getBooleanValue()) {&lt;br /&gt;           System.out.println("deep-equal == true");&lt;br /&gt;        }&lt;br /&gt;        else {&lt;br /&gt;           System.out.println("deep-equal == false");&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Following are the XML and XML Schema documents used for the above example.&lt;br /&gt;&lt;br /&gt;test1.xml&lt;br /&gt;&lt;pre&gt;&amp;lt;test&amp;gt;10.00&amp;lt;/test&amp;gt;&lt;br /&gt;&lt;/pre&gt;test2.xml&lt;br /&gt;&lt;pre&gt;&amp;lt;test&amp;gt;10&amp;lt;/test&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;test.xsd&lt;br /&gt;&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;schema xmlns="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;  &amp;lt;element name="test" type="double" /&amp;gt;&lt;br /&gt;&amp;lt;/schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For the above examples, if the schema type of element node "test" is xs:double then both the XML documents above are reported deep-equal (since the values 10 and 10.00 are same double values, and the element node was annotated with schema type xs:double and deep-equal function did a type aware comparison of XML documents). But if say the schema type of element node "test" is xs:string, then the XML documents shown above would be reported not deep-equal.&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6445061921880997223?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6445061921880997223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6445061921880997223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6445061921880997223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6445061921880997223'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/12/schema-based-xml-compare.html' title='Schema based XML compare'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8014999763234877075</id><published>2010-12-18T20:00:00.001+05:30</published><updated>2010-12-18T20:02:02.483+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Apache Xerces-J 2.11.0 released</title><content type='html'>I am happy to extend the announcement made by &lt;a href="http://xerces.apache.org/"&gt;Apache Xerces&lt;/a&gt; team few days ago, for the release of new version of &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; (2.11.0) (ref &lt;a href="http://markmail.org/message/oom75s3wpebfywh5"&gt;http://markmail.org/message/oom75s3wpebfywh5&lt;/a&gt;). This Xerces release specifically improves compliance to the XML Schema 1.1 language (the detailed release notes for Xerces-J 2.11.0 are available at, &lt;a href="http://xerces.apache.org/xerces2-j/releases.html"&gt;http://xerces.apache.org/xerces2-j/releases.html&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;On behalf of Xerces team I hope that this Xerces-J release would be found useful by the XML and XML Schema community.&lt;br /&gt;&lt;br /&gt;Refrences to XML Schema language:&lt;br /&gt;1. &lt;a href="http://www.w3.org/XML/Schema"&gt;http://www.w3.org/XML/Schema&lt;/a&gt; (XML Schema WG Home Page)&lt;br /&gt;2. &lt;a href="http://www.w3.org/TR/xmlschema11-1/"&gt;http://www.w3.org/TR/xmlschema11-1/&lt;/a&gt; (XML Schema 1.1 Structures specification)&lt;br /&gt;3. &lt;a href="http://www.w3.org/TR/xmlschema11-2/"&gt;http://www.w3.org/TR/xmlschema11-2/&lt;/a&gt; (XML Schema 1.1 Datatypes specification)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8014999763234877075?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8014999763234877075/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8014999763234877075' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8014999763234877075'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8014999763234877075'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/12/announcement-apache-xerces-j-2110.html' title='Apache Xerces-J 2.11.0 released'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4423649523254435468</id><published>2010-11-27T09:01:00.075+05:30</published><updated>2010-12-02T11:33:43.249+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XML Schema 1.1: complexType restriction rules</title><content type='html'>I've been excited enough to write now about the new rules that have been specified in &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; 1.1 spec regarding type derivations between XML Schema complexType definitions and what is &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;'s (it's XML Schema 1.1 engine) current compliance about this area of XML Schema language. In this blog post I'm currently covering XML schema complexType restriction derivations. I'll try to write about complexType extensions sometime later. I thought that this post might find audience interested in this topic (anyone is invited to write a comment to this blog post, which will help me to learn more about type derivations between XML schema complex types -- "i'm interested in both restriction and extension derivations", and can also give Xerces team useful feedback to improve Xerces in desired and compliant ways). Below are my findings from the XML Schema 1.1 spec about this topic, and also Xerces's compliance status in this regard (I acknowledge that my understanding may yet not be complete about these areas of the XML Schema language :).&lt;br /&gt;&lt;br /&gt;In XML Schema 1.0 language complex type restriction derivation rules are defined by schema particle restriction rules specified here, &lt;a href="http://www.w3.org/TR/xmlschema-1/#coss-particle"&gt;http://www.w3.org/TR/xmlschema-1/#coss-particle&lt;/a&gt;. There's a 5x5 table in this section which describes what constitute valid restrictions (and what schema type restrictions are forbidden) of XML schema particles.&lt;br /&gt;&lt;br /&gt;In XML Schema 1.1 all of these complexType derivation rules are replaced by sections &lt;a href="http://www.w3.org/TR/xmlschema11-1/#sec-derivation-ok-restriction"&gt;3.4.6.3 Derivation Valid (Restriction, Complex)&lt;/a&gt; and &lt;a href="http://www.w3.org/TR/xmlschema11-1/#sec-cos-content-act-restrict"&gt;3.4.6.4 Content Type Restricts (Complex Content)&lt;/a&gt;. In XML Schema 1.1 a mapping table (the 5x5 table) for particle restrictions is removed, and now a generic algorithm of subsumption relationship (a kind of containment or association relationship) of &lt;i&gt;default bindings (which is an abstract notion for element and attributes declarations along with wild-card attributes "strict", "lax" and "skip")&lt;/i&gt; is specified. The XML Schema 1.1 complexType subsumption rules are simpler and easy to remember, than the corresponding type derivation rules from XML Schema 1.0 spec. My personal understanding so far is that, the improved &lt;i&gt;default binding particle subsumption rules&lt;/i&gt; in XML Schema 1.1 make XML Schema 1.1 complexType restriction derivations largely compatible with corresponding type derivation rules in XML Schema 1.0, but the rules are now specified with better wordings.&lt;br /&gt;&lt;br /&gt;Below are various XML schema complexType restriction cases I've studied so far (and these have corresponding implementations in Xerces; the upcoming Xerces-J 2.11.0 release would have these features), the characteristics of which are also described and I'm trying to discover more of the rules in these areas of XML Schema language.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;xs:sequence, xs:choice and xs:all are possible compositors (which signify the notion of how we can compose schema particles in XML schema complexType definitions) in schema complexType's.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;A) SEQUENCE TO SEQUENCE RESTRICTIONS&lt;/b&gt;&lt;br /&gt;a.1 xs:element is derived from xs:any wild-card (both of these particles are part of an XML Schema sequence compositor). In this scenario cardinality of particles takes precedence than presence of a concrete element in derived type, when determining valid particle derivations.&lt;br /&gt;&lt;br /&gt;For e.g &amp;lt;xs:element name="x" type="xs:string" minOccurs="0"/&amp;gt; is not a valid restriction of &amp;lt;xs:any processContents="lax" /&amp;gt;, since the effective cardinality of element "x" (minOccurs="0" means that particle "x" is optional) is more than that of the wild-card particle (is mandatory).&lt;br /&gt;&lt;br /&gt;a.2 There must be a similar (i.e X-to-X where X is a positive numerical value) mapping of particles from a schema 'base' to 'derived' type. i.e a derived type cannot have less number of particles than those in base type, and a particle in derived type must validly derive (i.e is subsumed validly as per rules specified in XML Schema 1.1 spec) from the corresponding particle in base schema type.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;B) ALL TO SEQUENCE RESTRICTIONS&lt;/b&gt;&lt;br /&gt;b.1 This is a valid schema compositor (and of particles in them) restriction (i.e ordered from unordered restriction).&lt;br /&gt;&lt;br /&gt;For e.g sequence(b, a) and sequence(a, b) {order of particles in derived type doesn't matter} are valid restrictions of all(a, b).&lt;br /&gt;&lt;br /&gt;b.2 Identity of particles (recognized by QName of the particles) is recognized by the XML schema validator, and corresponding such particles must obey rules of restriction by cardinality (i.e an optional characteristic of particle does not make particle a valid restriction of a mandatory particle, where QName's of corresponding such particles in base and derived types are same).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;C) ALL TO ALL RESTRICTIONS&lt;/b&gt;&lt;br /&gt;c.1 This is an unordered to unordered kind restriction. Concrete element particle is an valid derivation of a wild-card particle.&lt;br /&gt;&lt;br /&gt;c.2 Cardinality of identical particles (having same QName's) in derived type must be same or less (which makes the derived particle validly derive from the corresponding particle from base type) than that in base type. Particle cardinalities take precedence over generic/concrete relationship between particles, when determining valid particle subsumptions.&lt;br /&gt;&lt;br /&gt;c.3 Number of leaf particles (which are essentially xs:element and xs:any wild-card's) in derived and base types must be equal.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;D) SEQUENCE TO ALL RESTRICTIONS&lt;/b&gt;&lt;br /&gt;This is not a valid schema compositor restriction (i.e from ordered to unordered).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;E) CHOICE TO SEQUENCE RESTRICTIONS&lt;/b&gt;&lt;br /&gt;e.1 Here are few examples explaining some of the rules for this category.&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;xs:element name="c" type="xs:string" /&amp;gt;&lt;br /&gt;  &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;is a valid restriction of&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:choice&amp;gt;  &lt;br /&gt;     &amp;lt;xs:any processContents="lax" /&amp;gt;&lt;br /&gt;     &amp;lt;xs:element name="b" type="xs:string" /&amp;gt;&lt;br /&gt;  &amp;lt;/xs:choice&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;(the element particle "c" is subsumable by the wild-card)&lt;br /&gt;&lt;br /&gt;e.2&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;xs:any processContents="lax" /&amp;gt;&lt;br /&gt;  &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;is not a valid restriction of&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:choice&amp;gt;         &lt;br /&gt;     &amp;lt;xs:element name="a" type="xs:string" /&amp;gt;&lt;br /&gt;     &amp;lt;xs:element name="b" type="xs:string" /&amp;gt;&lt;br /&gt;  &amp;lt;/xs:choice&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is so because a wild-card is not a valid subsumption of an element particle (i.e generic derivations from concrete elements is not a valid restriction, which in fact looks like an "type extension" concept).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;F) SEQUENCE TO CHOICE RESTRICTIONS&lt;/b&gt;&lt;br /&gt;Here's an example I can think over that correspond to use case of such kinds.&lt;br /&gt;&lt;pre&gt;   &lt;font color="green"&gt;&lt;br /&gt;   &amp;lt;xs:restriction base="TYPE_BASE"&amp;gt;&lt;br /&gt;      &amp;lt;xs:choice&amp;gt;&lt;br /&gt;         &amp;lt;xs:group ref="myGroup" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:choice&amp;gt;&lt;br /&gt;   &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;   &lt;/font&gt;&lt;br /&gt;   is a valid restriction of&lt;br /&gt;   &lt;font color="green"&gt;&lt;br /&gt;   &amp;lt;xs:complexType name="TYPE_BASE"&amp;gt;&lt;br /&gt;      &amp;lt;xs:group ref="myGroup" /&amp;gt;&lt;br /&gt;   &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;/font&gt;&lt;br /&gt;   &amp;lt;xs:group name="myGroup"&amp;gt;&lt;br /&gt;      &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="a" type="xs:string" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="b" type="xs:string" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;   &amp;lt;/xs:group&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But this is &lt;b&gt;not a useful schema type restriction&lt;/b&gt;, since the result of choice (i.e the schema particle produced from xs:choice) in derived type results only in one option, which is same as the contents of the sequence of the base type.&lt;br /&gt;&lt;br /&gt;Other than the above example I cannot envision any other useful example for practical scenarios for "sequence to choice" restriction. I would imagine that schema authors must not bother much about "sequence to choice" restriction scenarios, as this doesn't looks a good and useful schema design scenario (but I don't deny that people may find valid uses of this as well :).&lt;br /&gt;&lt;br /&gt;&lt;b&gt;G) CHOICE TO CHOICE RESTRICTIONS&lt;/b&gt;&lt;br /&gt;Here are few of the examples I can think of that satisfy this use-case (these I've found to be working fine with Xerces as well):&lt;br /&gt;&lt;br /&gt;g.1 choice(a, c) is not a valid restriction of choice(a, b). Because element "c" in derived type doesn't have a corresponding element particle in the base type.&lt;br /&gt;&lt;br /&gt;g.2 &lt;br /&gt;- choice(a, b) is a valid restriction of choice(a, wild-card processContents="lax"). If the wild-card can resolve to an element declaration that doesn't match element declaration "b", then this is NOT-A-VALID restriction.&lt;br /&gt;- choice(a, b) is a valid restriction of choice(a, wild-card processContents="strict") if wild-card can resolve to an element decleration for "b" OTHER-WISE not.&lt;br /&gt;&lt;br /&gt;g.3 choice(group name="myGroup", a) is a valid restriction of choice(group name="myGroup", xs:any processContents="lax"). Here model group instance is considered as a particle. But if the wild-card resolves to an element declaration that doesn't match element declaration "a", then this is NOT-A-VALID restriction.&lt;br /&gt;&lt;br /&gt;g.4 choice(group name="myGroup", a) is not a valid restriction of choice(group name="myGroup", &amp;lt;xs:any/&amp;gt;). But this is a valid restriction if wild-card &amp;lt;xs:any&amp;gt; can find definition of element "a" which can derive (i.e is a valid subsumption) to element "a" in the derived type.&lt;br /&gt;&lt;br /&gt;These are all the cases I can think of at the moment (enumerated A to G) which might occur for restriction between XML Schema 1.1 complexType's. I believe there would be few more complexType restriction cases which I'll try to post on this blog as I discover them.&lt;br /&gt;&lt;br /&gt;I hope that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4423649523254435468?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4423649523254435468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4423649523254435468' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4423649523254435468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4423649523254435468'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/11/xml-schema-11-complextype-restriction.html' title='XML Schema 1.1: complexType restriction rules'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6620550775077066758</id><published>2010-10-23T17:10:00.042+05:30</published><updated>2010-10-26T07:12:25.997+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD: schema type definition for empty XML content models</title><content type='html'>I'm inclined to write a little post, suggesting a correction (perhaps a better schema design) to an XML schema document I wrote in the blog post, &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches.html"&gt;http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches.html&lt;/a&gt; [1].&lt;br /&gt;&lt;br /&gt;In this post [1], I suggested the following XML schema type definition for empty content models (I assume there would not be any attributes on an element):&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:complexType name="EMPTY"&amp;gt; &lt;br /&gt;     &amp;lt;xs:complexContent&amp;gt; &lt;br /&gt;        &amp;lt;xs:restriction base="xs:anyType" /&amp;gt; &lt;br /&gt;     &amp;lt;/xs:complexContent&amp;gt; &lt;br /&gt;  &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Instead of the above schema type definition, I find the following (which is simpler I believe) schema type definition [2] (intending to constrain an XML element) to be better instead:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;    &amp;lt;xs:complexType/&amp;gt;&lt;br /&gt;  &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The element definition [2] above intends to validate an XML fragment like following:&lt;br /&gt;&lt;pre&gt;&amp;lt;X/&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the above example, I intend to suggest that there must not be any child nodes (and neither any XML attributes on an element) within element "X". Interestingly (nothing new really for people knowing XML schema language :) the &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; language, only allows constraining XML element and attribute nodes (and optionally these being XML namespace aware) and it doesn't bother about other XML infoset components like comments, processing-instructions and so on (which are present in XPath data model for example) &lt;b&gt;[A]&lt;/b&gt; -- this means that any other kinds of nodes, than XML elements and attributes are ignored by XML Schema language and a compliant XML schema validator. This nature &lt;b&gt;[A]&lt;/b&gt; of XML schema language is OK as I've learnt (there have been some nice discussions about all of this at &lt;a href="http://www.xml.org/xml-dev/"&gt;XML-DEV&lt;/a&gt; list in recent past).&lt;br /&gt;&lt;br /&gt;&lt;i&gt;2010-10-26:&lt;/i&gt; Here's another variant for definition of empty XML content models.&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:simpleType name="EMPTY"&amp;gt;&lt;br /&gt;     &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;        &amp;lt;xs:maxLength value="0"/&amp;gt;&lt;br /&gt;     &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;  &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This defines an XML schema 'simpleType' -- and &lt;i&gt;enforces content emptiness with the schema 'maxLength' facet on type xs:string&lt;/i&gt;, instead of a complex type as defined in the previous example. I'm more inclined to define element emptiness by an simpleType like above, since intent (and semantics) of schema simple types is never to define XML attributes, but those of complexType are.&lt;br /&gt;&lt;br /&gt;I hope the corrections I've shared in this post is appreciated by folks who've read my earlier post cited above [1].&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6620550775077066758?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6620550775077066758/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6620550775077066758' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6620550775077066758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6620550775077066758'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/10/xsd-schema-type-definition-for-empty.html' title='XSD: schema type definition for empty XML content models'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1240501898950529390</id><published>2010-10-10T22:15:00.059+05:30</published><updated>2010-10-16T14:02:49.178+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: XML schema design approaches cotd... PART 4</title><content type='html'>In this blog post i'm trying to describe (I find the subject matter here interesting enough to have a new blog post!) few more XML Schema (i'm trying to cook-up XSD 1.1 examples :) use-cases - using largely XSD 1.1 assertions which are now solvable with XML Schema 1.1 (for example constraining &lt;a href="http://en.wikipedia.org/wiki/Cardinality"&gt;cardinality&lt;/a&gt; of XML Schema xs:list items as described below), and as per my view-point couldn't be solved with XML Schema 1.0.&lt;br /&gt;&lt;br /&gt;I hope, &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; community might find few of the things here interesting.&lt;br /&gt;&lt;br /&gt;This post can be considered the PART 4 of the XML Schema 1.1 design series that I started couple of weeks ago. The previous parts of this series are available here:&lt;br /&gt;&lt;br /&gt;1) &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-schema-design-approaches-in-xsd.html"&gt;PART 1&lt;/a&gt;&lt;br /&gt;2) &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches.html"&gt;PART 2&lt;/a&gt;&lt;br /&gt;3) &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches_17.html"&gt;PART 3&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I'm using latest XML Schema 1.1 code-base from &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; SVN repos.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Use-case: (A)&lt;/b&gt;&lt;br /&gt;The examples in this post illustrate, &lt;b&gt;how we can constrain the cardinality of XML Schema 1.1 xs:list instance members&lt;/b&gt;, and &lt;i&gt;optionally constraining (just to verify myself how XSD 1.1 assertions behave in various combinations)&lt;/i&gt; few aspects of list members (like for example that, list items need to be even integers).&lt;br /&gt;&lt;br /&gt;Here's an XML instance document (this describes a simple enough list of integers encapsulated in an XML element "X"), which I'll use for illustrations in this post:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML 1]&lt;/i&gt; (named temp.xml)&lt;br /&gt;&lt;pre&gt;  &amp;lt;X&amp;gt;2 4 6 5 10 3&amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Below are few XML Schema 1.1 examples (with Schema 1.1 instructions highlighted with different color), and explanations from my point of view thereafter:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 1]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version='1.0'?&amp;gt;&lt;br /&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;            &amp;lt;xs:restriction base="INT_LIST"&amp;gt;&lt;br /&gt;              &lt;span style="background-color: #f9cb9c;"&gt;&amp;lt;xs:assertion test="count($value) le 5" /&amp;gt;&lt;br /&gt;&lt;/span&gt;            &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:complexType name="INT_LIST"&amp;gt;&lt;br /&gt;       &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;         &amp;lt;xs:restriction base="xs:anyType"&amp;gt;&lt;br /&gt;            &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;               &amp;lt;xs:list itemType="xs:integer" /&amp;gt;          &lt;br /&gt;            &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;            &lt;span style="background-color: #f9cb9c;"&gt;&amp;lt;xs:assert test="every $x in $value satisfies ($x mod 2 = 0)" /&amp;gt;&lt;/span&gt;&lt;br /&gt;         &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;       &amp;lt;/xs:simpleContent&amp;gt; &lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 2]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version='1.0'?&amp;gt;&lt;br /&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;        &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;          &amp;lt;xs:restriction base="INT_LIST"&amp;gt;&lt;br /&gt;             &lt;span style="background-color: #f9cb9c;"&gt;&amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;&lt;/span&gt;          &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;        &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:simpleType name="INT_LIST"&amp;gt;&lt;br /&gt;       &amp;lt;xs:list itemType="xs:integer" /&amp;gt;&lt;br /&gt;     &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 3]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version='1.0'?&amp;gt;&lt;br /&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;          &amp;lt;xs:extension base="INT_LIST"&amp;gt;&lt;br /&gt;             &lt;span style="background-color: #f9cb9c;"&gt;&amp;lt;xs:assert test="count($value) le 5" /&amp;gt;&lt;/span&gt;&lt;br /&gt;          &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;        &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:simpleType name="INT_LIST"&amp;gt;&lt;br /&gt;       &amp;lt;xs:list itemType="xs:integer" /&amp;gt;&lt;br /&gt;    &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here are results of XML instance (of document &lt;i&gt;[XML 1]&lt;/i&gt;) validation, with the specified schema's:&lt;br /&gt;&lt;br /&gt;1. When XML document (&lt;i&gt;[XML 1]&lt;/i&gt;) is validated by the schema &lt;i&gt;[XML Schema 1]&lt;/i&gt;, we get following validation outcomes with Xerces:&lt;br /&gt;&lt;i&gt;[Error] temp.xml:1:20: cvc-assertion.3.13.4.1: Assertion evaluation ('every $x in $value satisfies ($x mod 2 = 0)') for element 'X' with type 'INT_LIST' did not succeed.&lt;br /&gt;[Error] temp.xml:1:20: cvc-assertion.3.13.4.1: Assertion evaluation ('count($value) le 5') for element 'X' with type '#anonymous' did not succeed.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;2. When XML document (&lt;i&gt;[XML 1]&lt;/i&gt;) is validated by the schema &lt;i&gt;[XML Schema 2]&lt;/i&gt;, we get following validation outcomes (with Xerces):&lt;br /&gt;&lt;i&gt;[Error] temp.xml:1:20: cvc-assertion.3.13.4.1: Assertion evaluation ('$value mod 2 = 0') for element 'X' with type '#anonymous' did not succeed. Assertion failed for an xs:list member value '5'.&lt;br /&gt;[Error] temp.xml:1:20: cvc-assertion.3.13.4.1: Assertion evaluation ('$value mod 2 = 0') for element 'X' with type '#anonymous' did not succeed. Assertion failed for an xs:list member value '3'.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;3. When XML document (&lt;i&gt;[XML 1]&lt;/i&gt;) is validated by the schema &lt;i&gt;[XML Schema 3]&lt;/i&gt;, we get following validation outcomes (with Xerces):&lt;br /&gt;&lt;i&gt;[Error] temp.xml:1:20: cvc-assertion.3.13.4.1: Assertion evaluation ('count($value) le 5') for element 'X' with type '#anonymous' did not succeed.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Here's some quick analysis from my point of view, with regards to what I wanted to achieve with these use-cases (A):&lt;br /&gt;&lt;br /&gt;The XML Schema 1.1 assertions XPath 2.0 context variable "$value" has a type annotation xs:anyAtomicType*.&lt;br /&gt;&lt;br /&gt;1. The first validation result (1. above) illustrates that every item of xs:list needs to be an even integer, and number of list items are constrained to be maximum "5" (this is a sample "max" limit on number of list items).&lt;br /&gt;&lt;br /&gt;2. I intended to use validation results 2. and 3. in combination doing an boolean "AND" of them, essentially to have same XML instance validation objective as case 1. The boolean "AND" of two schema validations can be achieved with for example, Java JAXP validation API. I wrote XML Schema document, &lt;i&gt;[XML Schema 2]&lt;/i&gt; to have the XML Schema validator return each individual list item, which do not pass test of mathematical evenness (this was not entirely achieved with schema document &lt;i&gt;[XML Schema 1]&lt;/i&gt; -- where the schema detected an evenness failure for whole list instance, but didn't report every individual list item which didn't pass evenness test).&lt;br /&gt;&lt;br /&gt;I hope the intent of the use-case described here, and the solutions offered are explained clear enough for XML Schema audience.&lt;br /&gt;&lt;br /&gt;Thanks for reading, and as usual I hope that this blog post was interesting!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1240501898950529390?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1240501898950529390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1240501898950529390' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1240501898950529390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1240501898950529390'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/10/xsd-11-xml-schema-design-approaches.html' title='XSD 1.1: XML schema design approaches cotd... PART 4'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1492429307443955199</id><published>2010-09-05T22:48:00.037+05:30</published><updated>2010-09-10T08:56:02.055+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: Xerces-J implementation updates</title><content type='html'>Over the past one or two months, there have been few interesting changes happening at Xerces-J &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; 1.1 implementation. I feel obliged to share these enhancements with the XML Schema community, and also with folks at &lt;a href="http://www.eclipse.org/webtools/"&gt;Eclipse WTP&lt;/a&gt; (where we enhanced few "schema aware" components of &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;PsychoPath XPath 2.0 engine&lt;/a&gt;, to support these recent Xerces enhancements -- I think we improved the design of typed values of XML element and attribute &lt;a href="http://www.w3.org/TR/xpath-datamodel/"&gt;XDM&lt;/a&gt; nodes in PsychoPath XPath2 engine, in case the XDM node has a type annotation of kind &lt;a href="http://www.w3.org/TR/xmlschema11-2/#xr-defn"&gt;XML Schema simpleType&lt;/a&gt;, with varieties list or union).&lt;br /&gt;&lt;br /&gt;Here's a summary of XML Schema 1.1 implementation changes that have recently been completed with Xerces (available at Xerces SVN repos as of now), which are planned to be part of the Xerces-J 2.11.0 release, planned to take please during November 2010 time frame.&lt;br /&gt;&lt;br /&gt;1. &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; now has a complete implementation of &lt;a href="http://www.w3.org/TR/xmlschema11-1/#cip"&gt;XML Schema 1.1 conditional inclusion&lt;/a&gt; functionality. The Xerces-J 2.10.0 release had implementation of XML Schema 1.1 conditional inclusion vc:minVersion and vc:maxVersion attributes. Xerces-J now supports all of "conditional inclusion" attributes as specified by the XML Schema 1.1 spec. The "conditional inclusion" attributes that are now newly supported in Xerces-J are: vc:typeAvailable, vc:typeUnavailable, vc:facetAvailable and vc:facetUnavailable. All of XML Schema 1.1 built-in types and facets are now supported by Xerces-J related to XML Schema 1.1 "conditional inclusion" components.&lt;br /&gt;&lt;br /&gt;2. There are few interesting changes that have happened to Xerces-J &lt;a href="http://www.w3.org/TR/xmlschema11-1/#cAssertions"&gt;XML Schema 1.1 assertions&lt;/a&gt; implementation as well, that are planned to be part of Xerces-J 2.11.0 release. Xerces now has an improved assertions evaluation processing on XML Schema (1.1) simple types, with varieties 'list' and 'union'.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2.1 Enhancements to assertions evaluation on simpleType -&gt; list:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Here's an example of XML Schema 1.1 assertions on an xs:list schema component:&lt;br /&gt;&lt;i&gt;[XML Schema 1]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;   &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;      &amp;lt;xs:element name="Example" type="EXAMPLE_LIST" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:simpleType name="EXAMPLE_LIST"&amp;gt;&lt;br /&gt;         &amp;lt;xs:list&amp;gt;&lt;br /&gt;            &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;               &amp;lt;xs:restriction base="xs:integer"&amp;gt;&lt;br /&gt;                  &amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;               &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;            &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;         &amp;lt;/xs:list&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;/xs:schema&amp;gt; &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If an XML instance document has a structure something like following:&lt;br /&gt;&lt;i&gt;[XML 1]&lt;/i&gt;&lt;br /&gt;&amp;lt;Example&amp;gt;1 2 3&amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;br /&gt;And if this XML instance document (&lt;i&gt;[XML 1]&lt;/i&gt;) is validated by the above XML schema (&lt;i&gt;[XML Schema 1]&lt;/i&gt;), Xerces-J would report error messages like following (assuming the name of XML document was, test.xml):&lt;br /&gt;&lt;i&gt;[Error] test.xml:1:25: cvc-assertion.3.13.4.1: Assertion evaluation ('$value mod 2 = 0') for element 'Example' with type '#anonymous' did not succeed. Assertion failed for an xs:list member value '1'.&lt;br /&gt;[Error] test.xml:1:25: cvc-assertion.3.13.4.1: Assertion evaluation ('$value mod 2 = 0') for element 'Example' with type '#anonymous' did not succeed. Assertion failed for an xs:list member value '3'.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;An assertion must evaluate on every &lt;i&gt;'simpleType -&gt; list'&lt;/i&gt; item (which is validated by the itemType of xs:list) in an XML instance document. Xerces now does this, and needed error messages are displayed in case of schema assertion failures.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;2.2 Enhancements to assertions evaluation on simpleType -&gt; union:&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Here's an example of XML Schema 1.1 assertions on an xs:union schema component:&lt;br /&gt;&lt;i&gt;[XML Schema 2]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;   &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:element name="Example"&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;            &amp;lt;xs:union memberTypes="MYDATE xs:integer" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;      &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:simpleType name="MYDATE"&amp;gt;&lt;br /&gt;         &amp;lt;xs:restriction base="xs:date"&amp;gt;&lt;br /&gt;            &amp;lt;xs:assertion test="$value lt current-date()" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If an XML instance document has a structure something like following:&lt;br /&gt;[XML 2]&lt;br /&gt;&amp;lt;Example&amp;gt;2010-12-05&amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;br /&gt;And this instance document is validated by the schema document, &lt;i&gt;[XML Schema 2]&lt;/i&gt; the following error message is displayed by Xerces:&lt;br /&gt;&lt;i&gt;[Error] temp.xml:1:30: cvc-assertion.union.3.13.4.1: Element 'Example' with value '2010-12-05' is not locally valid. One or more of the assertion facets on an element's schema type, with variety union, have failed.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Xerces tried to validate an atomic value '2010-12-05' both with schema types xs:integer and MYDATE. Since none of these types could successfully validate this atomic value, and an assertion failed in the process of these validation checks, the relevant assertion failure was reported by Xerces.&lt;br /&gt;&lt;br /&gt;If the XML schema, &lt;i&gt;[XML Schema 2]&lt;/i&gt; tries to validate the XML instance document:&lt;br /&gt;&amp;lt;example&amp;gt;10&amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;br /&gt;no validation failures are reported in this case, since an atomic value '10' conforms to the schema type xs:integer, which results in an overall validation success of the atomic value with an 'union' schema type. &lt;br /&gt;&lt;br /&gt;I'm ending this blog post now. Stay tuned for more news here :)&lt;br /&gt;&lt;br /&gt;And I hope, that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1492429307443955199?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1492429307443955199/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1492429307443955199' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1492429307443955199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1492429307443955199'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/09/xml-schema-11-xerces-j-implementation.html' title='XSD 1.1: Xerces-J implementation updates'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7174214421662170804</id><published>2010-07-17T08:24:00.009+05:30</published><updated>2010-07-19T21:24:21.648+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: XML schema design approaches cotd... PART 3</title><content type='html'>I'm continuing with the &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; design thoughts series, with the third part here. The first two parts are available here:&lt;br /&gt;1) &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-schema-design-approaches-in-xsd.html"&gt;PART 1&lt;/a&gt; &lt;br /&gt;2) &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches.html"&gt;PART 2&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All the examples here have been tested with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; 2.10.0.&lt;br /&gt;&lt;br /&gt;(I'm disclaiming in the beginning, that examples presented in this blog post are somewhat fictitious and may not serve a real life use-case. These examples are kind of cooked-up to only illustrate XML Schema 1.1 constructs, and some of design thinking behind them. I also refer at lot of places a phrase "element particles". This simply means XML elements, but "particles" is a formal term defined by the XML Schema spec, designating XML schema components having minOccurs and maxOccurs attributes -- if minOccurs/maxOccurs attributes are absent, then these have default values for the relevant schema components)&lt;br /&gt;&lt;br /&gt;I'm presenting a sample 1.1 XML schema with corresponding XML document first, and then attempting trying to reflect on the inherent design from my point of view in these examples:&lt;br /&gt;&lt;br /&gt;XML Schema 1.1 specific constructs are emphasized with a different color.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML1]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;Book&amp;gt;&lt;br /&gt;     &amp;lt;name&amp;gt;XML in a Nutshell&amp;lt;/name&amp;gt;&lt;br /&gt;     &amp;lt;ISBN&amp;gt;AB-1001&amp;lt;/ISBN&amp;gt;&lt;br /&gt;     &amp;lt;author&amp;gt;Jimmy&amp;lt;/author&amp;gt;&lt;br /&gt;     &amp;lt;NoPages&amp;gt;100&amp;lt;/NoPages&amp;gt;&lt;br /&gt;  &amp;lt;/Book&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 1]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;     &amp;lt;xs:element name="Book"&amp;gt;&lt;br /&gt;        &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;          &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;            &amp;lt;xs:extension base="BOOK_FRAGMENT"&amp;gt;&lt;br /&gt;               &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:openContent&amp;gt;&lt;br /&gt;                 &amp;lt;xs:any processContents="lax" /&amp;gt;&lt;br /&gt;               &amp;lt;/xs:openContent&amp;gt;&lt;/span&gt;&lt;br /&gt;               &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="not(* except (name, author, ISBN, NoPages)) and &lt;br /&gt;                                 (if (ISBN)&lt;br /&gt;                                    then not(ISBN/*) &lt;br /&gt;                                    else true()) and &lt;br /&gt;                                 (if (NoPages) &lt;br /&gt;                                     then (not(NoPages/*) and (NoPages/text() castable as xs:positiveInteger))&lt;br /&gt;                                     else true())" /&amp;gt;&lt;/span&gt;    &lt;br /&gt;            &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;          &amp;lt;/xs:complexContent&amp;gt;          &lt;br /&gt;        &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:complexType name="BOOK_FRAGMENT"&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="name" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="author" type="xs:string" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The following use-case requirements motivated me to write this sample (I'm also trying to reflect on the schema design choices I've made, about which I surely invite comments from the readers -- if you've patience to read this post and respond!):&lt;br /&gt;1. XML Schema 1.0 has a limitation that, when a complex type (having sequence or choice particles) is derived by extension then a derived complex type can only add element particles at the end of an element list (within the base type). &lt;i&gt;Supposing that we want to re-use a complex type (having a sequence of element particles) by deriving it with extension, and need to add additional element particles say any-where in between the elements of the base type&lt;/i&gt;. This is what the above XML schema (&lt;i&gt;XML Schema 1&lt;/i&gt;) example intends to do; and the above schema does indeed validates successfully the corresponding XML document presented above (&lt;i&gt;XML1&lt;/i&gt;).&lt;br /&gt;&lt;br /&gt;2. A key design decision in the above schema (&lt;i&gt;XML Schema 1&lt;/i&gt;) is to use the XML Schema 1.1 "openContent" instruction (newly introduced in 1.1 version). The use of XSD 1.1 assertions here is optional, but is very practical to do so (which I'll try to explain!). An XML schema "openContent" instruction is essentially a wrapper around xs:any wild-card, producing the same effect as xs:any wild-card but has an interleave or a suffix appending behavior (please feel free to read the &lt;a href="http://www.w3.org/TR/xmlschema11-1/"&gt;XML Schema 1.1&lt;/a&gt; spec to learn more about XSD 1.1 open contents. Or perhaps if you want a lighter [but brilliant] explanation, you may read Roger L. Costello's XML Schema 1.1 write-up &lt;a href="http://www.xfront.com/xml-schema-1-1/"&gt;available here&lt;/a&gt;).&lt;br /&gt;The XML Schema 1.1 spec defines an "openContent" instruction as following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;openContent&lt;br /&gt;     id = ID&lt;br /&gt;     mode = (none | interleave | suffix) : interleave&lt;br /&gt;     {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;     Content: (annotation?, any?)&lt;br /&gt;  &amp;lt;/openContent&amp;gt;&lt;br /&gt;&lt;/pre&gt;It is an openContent instruction with "interleave" mode (which is the default openContent mode), which enables adding additional element particles interspersed between base type's element particles.&lt;br /&gt;&lt;br /&gt;3. In the above example, the XML elements "ISBN" and "NoPages" are added to the base type's element particles which are not appended at the end of base type's elements, but can be added anywhere within the resulting XML content model. For this particular example, the placement of XML elements coming from the derived complex type are arbitrary, and is done to only illustrate the workings of "openContent" instruction in "interleave" mode.&lt;br /&gt;&lt;br /&gt;4. It's interesting to see the benefit of XSD 1.1 assertions here. The assertions here are able to impose certain constraints on the resultant content model (otherwise the content model is kind-of wide open with no restrictions). The assertions in the above schema document (&lt;i&gt;XML Schema 1&lt;/i&gt;) mean:&lt;br /&gt;&amp;nbsp;&amp;nbsp;a) The resulting content model can only have XML elements -&amp;gt; "name", "author", "ISBN" and "NoPages".&lt;br /&gt;&amp;nbsp;&amp;nbsp;b) The element "ISBN" needs to be an atomic string value, and the element "NoPages" needs to be an xs:positiveInteger value.&lt;br /&gt;&lt;br /&gt;I'm presenting below another XML schema variant (than the example above -- &lt;i&gt;XML Schema 1&lt;/i&gt;), which solves the same problem as described above, but in a slightly different way (with advantages and disadvantages described after the example):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 2]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;      &amp;lt;xs:element name="Book"&amp;gt;&lt;br /&gt;         &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;            &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;               &amp;lt;xs:extension base="BOOK_FRAGMENT"&amp;gt;&lt;br /&gt;                  &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:openContent&amp;gt;&lt;br /&gt;                     &amp;lt;xs:any processContents="strict"/&amp;gt;&lt;br /&gt;                  &amp;lt;/xs:openContent&amp;gt;&lt;br /&gt;                  &amp;lt;xs:assert test="count(distinct-values(for $elem in (* except (name, author)) return $elem/name())) = count(for $elem in (* except (name, author)) return $elem/name())"/&amp;gt;&lt;/span&gt;       &lt;br /&gt;               &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;            &amp;lt;/xs:complexContent&amp;gt;          &lt;br /&gt;         &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;      &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:complexType name="BOOK_FRAGMENT"&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="name" type="xs:string"/&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="author" type="xs:string"/&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:element name="ISBN" type="xs:string" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:element name="NoPages" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The example XML document for this schema (&lt;i&gt;XML Schema 2&lt;/i&gt;) remains same (&lt;i&gt;XML1&lt;/i&gt;). Here are the advantages (and unfortunately a little disadvantage as well, with a suggested workaround for the drawback...) of the sample, &lt;i&gt;XML Schema 2&lt;/i&gt;:&lt;br /&gt;1. Here we are using xs:any wild-card with processContents="strict" mode (the earlier example used the wild-card with "lax" mode) and providing the corresponding element declarations in the schema (the last two element declarations). This approach has advantage that, the content model of elements "ISBN" and "NoPages" are enforced natively by the XML schema engine, and the schema author doesn't have to implement the content model constraints herself/himself (for example, that an element is empty and has an atomic value) -- say via assertions. This approach is more robust, than trying to achieve the similar effect with assertions.&lt;br /&gt;&lt;br /&gt;2. The assertion in schema document, &lt;i&gt;[XML Schema 2]&lt;/i&gt; enforces that elements in the sequence could occur only once. This is accomplished by this simple algorithm:&lt;br /&gt;count(distinct-values(names...)) = count(names...)&lt;br /&gt;&lt;br /&gt;3. The only drawback I foresee with &lt;i&gt;XML Schema 2&lt;/i&gt;, is that elements "ISBN" and "NoPages" are now global elements (which is necessary to have xs:any wild-card to work with processContents="strict" mode). This has implication that following XML documents would be reported valid as well, by the schema document &lt;i&gt;XML Schema 2&lt;/i&gt;:&lt;br /&gt;&lt;pre&gt;  &amp;lt;ISBN&amp;gt;AB-1001&amp;lt;/ISBN&amp;gt;&lt;br /&gt;&lt;/pre&gt;AND&lt;br /&gt;&lt;pre&gt;  &amp;lt;NoPages&amp;gt;100&amp;lt;/NoPages&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is a side-effect of schema document &lt;i&gt;XML Schema 2&lt;/i&gt;, which I myself personally don't seem to like :(&lt;br /&gt;&lt;br /&gt;To solve this limitation, I can imagine there could be a workaround as following:&lt;br /&gt;We could perform two validations in sequence. One with the schema document, &lt;i&gt;[XML Schema 2]&lt;/i&gt; (let's call this validation V1) and the second one with the following schema document (let's call this validation result V2):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 3]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;      &lt;br /&gt;      &amp;lt;xs:element name="ISBN" type="xs:string" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;      &amp;lt;xs:element name="NoPages" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is kind of a little validation pipeline. The complete/end-to-end (which usually means, that this has domain meaning) schema validation succeeds in entirety, if validation V1 succeeds but V2 doesn't (I imagine, that this kind-of pipeline operation could be enforced by a host language, like Java using the XML Schema JAXP APIs).&lt;br /&gt;&lt;br /&gt;Thanks for reading!&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7174214421662170804?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7174214421662170804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7174214421662170804' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7174214421662170804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7174214421662170804'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches_17.html' title='XSD 1.1: XML schema design approaches cotd... PART 3'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8908380686245157551</id><published>2010-07-11T10:00:00.009+05:30</published><updated>2010-07-18T07:07:13.333+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: XML schema design approaches cotd... PART 2</title><content type='html'>I'm continuing with the &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; design approaches series, I started in the &lt;a href="http://mukulgandhi.blogspot.com/2010/07/xsd-11-schema-design-approaches-in-xsd.html"&gt;previous blog post&lt;/a&gt;. Here's the second post in this series.&lt;br /&gt;&lt;br /&gt;Here's a description of the use-case I'll be illustrating in this post, with both XML Schema 1.0 and 1.1 examples:&lt;br /&gt;&lt;br /&gt;We need to write an XML Schema for the following XML content model:&lt;br /&gt;&lt;pre&gt;  colors&lt;br /&gt;    -&amp;gt; (violet | indigo | blue | green | yellow | orange | red)+&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here the words "colors", "violet" etc represent XML elements, and they have no attributes and are empty. The above content model means, that children of element "colors" can repeat and are unordered, and at-least one of them is required. &lt;br /&gt;&lt;br /&gt;Therefore following XML document is a valid instance according to this content model:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML1]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;colors&amp;gt;&lt;br /&gt;     &amp;lt;violet/&amp;gt;&lt;br /&gt;     &amp;lt;indigo/&amp;gt;&lt;br /&gt;     &amp;lt;blue/&amp;gt;&lt;br /&gt;     &amp;lt;green/&amp;gt;&lt;br /&gt;     &amp;lt;yellow/&amp;gt;&lt;br /&gt;     &amp;lt;orange/&amp;gt;&lt;br /&gt;     &amp;lt;red/&amp;gt;&lt;br /&gt;  &amp;lt;/colors&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;AND for example, the following XML document is valid as well, as per the content model described above (here the element "colors" have less children than the previous example, and some of children of "colors" occur more than once):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML2]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;colors&amp;gt;&lt;br /&gt;     &amp;lt;violet/&amp;gt;&lt;br /&gt;     &amp;lt;indigo/&amp;gt;&lt;br /&gt;     &amp;lt;blue/&amp;gt;&lt;br /&gt;     &amp;lt;green/&amp;gt;&lt;br /&gt;     &amp;lt;green/&amp;gt;&lt;br /&gt;  &amp;lt;/colors&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here are two XML schema examples that express the above XML content model constraints:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 1]&lt;/i&gt; (written in XML Schema 1.0)&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;     &amp;lt;xs:element name="colors"&amp;gt;&lt;br /&gt;        &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;           &amp;lt;xs:choice maxOccurs="unbounded"&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="violet" type="EMPTY" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="indigo" type="EMPTY" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="blue" type="EMPTY" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="green" type="EMPTY" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="yellow" type="EMPTY" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="orange" type="EMPTY" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:element name="red" type="EMPTY" /&amp;gt;     &lt;br /&gt;           &amp;lt;/xs:choice&amp;gt;&lt;br /&gt;        &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:complexType name="EMPTY"&amp;gt; &lt;br /&gt;        &amp;lt;xs:complexContent&amp;gt; &lt;br /&gt;          &amp;lt;xs:restriction base="xs:anyType" /&amp;gt; &lt;br /&gt;        &amp;lt;/xs:complexContent&amp;gt; &lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;[XML Schema 2]&lt;/i&gt; (written in XML Schema 1.1 -- the 1.1 specific constructs are displayed with a different color)&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;     &amp;lt;xs:element name="colors"&amp;gt;&lt;br /&gt;        &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;           &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:any maxOccurs="unbounded" processContents="lax" /&amp;gt;&lt;br /&gt;           &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;           &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="every $x in */name() satisfies ($x = &lt;br /&gt;                              ('violet','indigo','blue','green','yellow','orange','red'))" /&amp;gt;&lt;br /&gt;           &amp;lt;xs:assert test="every $x in * satisfies not($x/node())" /&amp;gt;&lt;/span&gt;&lt;br /&gt;        &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here's some quick analysis from my point of view, about the differences between the above schema approaches, and if any of the above approaches is better than the other one:&lt;br /&gt;1) &lt;i&gt;"XML Schema 1"&lt;/i&gt; is written in a familiar 1.0 style, so people who want to stick with 1.0 can still adopt this technique. We can observe, that the first schema is a little more verbose than the second one, which I see as one of the advantage of the second one.&lt;br /&gt;&lt;br /&gt;2) If you are comfortable writing the XPath 2.0 expressions, then there are virtually too many possibilities to express schema validation constraints with XSD 1.1 assertions, which is really lots of power in the hands of the schema author!&lt;br /&gt;&lt;br /&gt;3) Personally speaking, I find the second way of writing the XML schema (&lt;i&gt;"XML Schema 2"&lt;/i&gt;) a really cool NEW way to express these validation constrains. I'm not suggesting that the 1st way is not really good! That technique has great value, in it's own sense and has stood the tests of time. I find the second technique a more natural description from the schema author, to express the logic of the use-case in question.&lt;br /&gt;&lt;br /&gt;4) One the possibilities I now foresee with XML Schema 1.1, is that schema author could impose quite a bit of constraints on xs:any wild-card instruction via assertions (which is particularly useful with processContents="lax" mode of the xs:any wild-card). A point worth observing is that with processContents="strict" mode of the xs:any wild-card, assertions are not really useful because, the schema validator would strictly validate the XML element with an element declaration, which must be provided by the schema author to satisfy the processContents="strict" mode of the wild-card (and assertions here would actually interfere with the available element declarations, which to my opinion is not a good design). With processContents="skip" mode of the xs:any wild-card, assertions would always fail (and the XML instance would become invalid), because the concerned XML elements would be discarded by the XML schema validator, and consequently these elements would not be part of the XPath data-model tree, on which assertions operate.&lt;br /&gt;&lt;br /&gt;And needless to mention, &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; handles all the above examples fine!&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8908380686245157551?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8908380686245157551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8908380686245157551' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8908380686245157551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8908380686245157551'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/07/xsd-11-xml-schema-design-approaches.html' title='XSD 1.1: XML schema design approaches cotd... PART 2'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3701518897670714338</id><published>2010-07-03T20:05:00.008+05:30</published><updated>2010-07-27T21:24:28.854+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: XML schema design approaches in XSD 1.1 world... PART 1</title><content type='html'>I'm thinking to write a series of posts (since writing too many ideas in one post could be boring to read, and could be quite voluminous for one post. I'll try to make sure, that these blog posts starting from this one have cross-references between them for related issues AND I'll convey in some future blog post, when I'm stopping writing this series!) only on XML schema design, given the XML Schema 1.1 constructs. I'll try to reflect why &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; 1.1 is essential for certain use-cases, and where XML Schema 1.0 falls short.&lt;br /&gt;&lt;br /&gt;It is possible, that there may be a blog post unrelated to this series between these posts. When this series completes, I'll try to summarize the ideas at the end, to make the whole series available as an unit.&lt;br /&gt;&lt;br /&gt;I'm disclaiming in the beginning, that any advice offered here may not necessarily be best. Improvements are generally always possible! Any feedback would be great (about the correctness of anything described here, alternative ideas OR anything else).&lt;br /&gt;&lt;br /&gt;To start with the 1st post in this series, here's a little background about the use-case I'm describing in the subsequent paragraphs:&lt;br /&gt;I've been reading the book &lt;a href="http://www.amazon.com/DB2-pureXML-Cookbook-Master-Hybrid/dp/0138150478"&gt;"DB2 pureXML Cookbook: Master the Power of the IBM Hybrid Data Server"&lt;/a&gt; [1] recently by Matthias Nicola (a member of &lt;a href="http://www-01.ibm.com/software/data/db2/xml/"&gt;DB2 pureXML&lt;/a&gt; team). This book describes an example (in chapter 2) as follows.&lt;br /&gt;A physical object could be described by two possible XML content models as follows:&lt;br /&gt;&lt;br /&gt;a) Metadata as values, aka Name/Value Pairs (often bad):&lt;br /&gt;&lt;pre&gt;  &amp;lt;object type="car"&amp;gt;&lt;br /&gt;    &amp;lt;field name="brand" value="Honda" /&amp;gt;&lt;br /&gt;    &amp;lt;field name="price" value="5000" /&amp;gt;&lt;br /&gt;    &amp;lt;field name="currency" value="USD" /&amp;gt;&lt;br /&gt;    &amp;lt;field name="year" value="2002" /&amp;gt;&lt;br /&gt;  &amp;lt;/object&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;b) Metadata as element names (good):&lt;br /&gt;&lt;pre&gt;  &amp;lt;car&amp;gt;&lt;br /&gt;    &amp;lt;brand&amp;gt;Honda&amp;lt;/brand&amp;gt;&lt;br /&gt;    &amp;lt;price currency="USD"&amp;gt;5000&amp;lt;/price&amp;gt;&lt;br /&gt;    &amp;lt;year&amp;gt;1996&amp;lt;/year&amp;gt;&lt;br /&gt;  &amp;lt;/car&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I wouldn't describe here why one of the above XML design approaches is good or bad. This is described well in the book cited above [1], which I would encourage folks to read (the books has some nice explanation about DB2 pureXML as well).&lt;br /&gt;&lt;br /&gt;Let's say we want to build an XSD schema, for the XML document (a) above. To start with, one of the design decisions I took is, to define a set of XML Schema types with a hierarchy as following:&lt;br /&gt;&lt;pre&gt;  OBJECT&lt;br /&gt;     -&amp;gt; OBJECT_ON_SALE&lt;br /&gt;            -&amp;gt; CAR&lt;br /&gt;            -&amp;gt; BOOK&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The other few design decisions I've taken are as following:&lt;br /&gt;1) We'll use XSD 1.1 type-alternatives to select between different schema types, depending on value of the attribute object/@type.&lt;br /&gt;2) We'll use an hierarchy of XSD 1.1 assertions definitions, to enforce certain validation constraints.&lt;br /&gt;&lt;br /&gt;The meaning of these design decisions would likely become clear to us, by looking at the XML instance and schema document I'm describing below:&lt;br /&gt;&lt;br /&gt;The sample XML instance I propose is as following:&lt;br /&gt;&lt;i&gt;[XML1]&lt;/i&gt; (this is same as XML instance "a" above, and is repeated here for convenience)&lt;br /&gt;&lt;pre&gt;  &amp;lt;object type="car"&amp;gt;&lt;br /&gt;     &amp;lt;field name="brand" value="Honda" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="price" value="5000" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="currency" value="USD" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="year" value="2002" /&amp;gt;&lt;br /&gt;  &amp;lt;/object&amp;gt;&lt;br /&gt;&lt;/pre&gt;OR&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[XML2]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;object type="book"&amp;gt;&lt;br /&gt;     &amp;lt;field name="title" value="XML in a Nutshell" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="author" value="Jimmy" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="author" value="Nick" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="publisher" value="Prentice Hall" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="price" value="15" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="currency" value="USD" /&amp;gt;&lt;br /&gt;     &amp;lt;field name="year" value="2008" /&amp;gt;&lt;br /&gt;  &amp;lt;/object&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I propose the following XSD 1.1 schema (the 1.1 specific constructs are highlighted with a different color), that is designed to validate both of above XML instance documents (after which I'll try to analyze few design elements of this schema):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;[SCHEMA1]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;             xmlns:xerces="http://xerces.apache.org"&amp;gt;&lt;br /&gt; &lt;br /&gt;     &amp;lt;xs:element name="object" type="OBJECT"&amp;gt;&lt;br /&gt;       &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:alternative test="@type='book'" type="BOOK" /&amp;gt;&lt;br /&gt;       &amp;lt;xs:alternative test="@type='car'" type="CAR" /&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt; &lt;br /&gt;     &amp;lt;xs:complexType name="BOOK"&amp;gt;&lt;br /&gt;        &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;           &amp;lt;xs:extension base="OBJECT_ON_SALE"&amp;gt;&lt;br /&gt;              &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="field/@name = 'title' and&lt;br /&gt;                               field/@name = 'author' and&lt;br /&gt;                               field/@name = 'publisher' and&lt;br /&gt;                               field/@name = 'year'"&lt;br /&gt;                         xerces:message="For a book the fields title/author/publisher/year are mandatory" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:assert test="xs:int(field[@name = 'year']/@value) gt 1900 and &lt;br /&gt;                               xs:int(field[@name = 'year']/@value) lt 2011"&lt;br /&gt;                         xerces:message="A book's publication year must be between 1900 and 2011" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:assert test="count(field[not(@name = 'author')]) = &lt;br /&gt;                               count(distinct-values(field[not(@name = 'author')]/string(@name)))" &lt;br /&gt;                         xerces:message="A book can have multiple authors, but none of other fields of a book can occur twice" /&amp;gt;&lt;/span&gt;&lt;br /&gt;           &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;        &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt; &lt;br /&gt;     &amp;lt;xs:complexType name="CAR"&amp;gt;&lt;br /&gt;        &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;           &amp;lt;xs:extension base="OBJECT_ON_SALE"&amp;gt;&lt;br /&gt;              &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="field/@name = 'brand' and&lt;br /&gt;                               field/@name = 'year'" &lt;br /&gt;                         xerces:message="For a car the fields brand/year are required" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:assert test="xs:int(field[@name = 'year']/@value) gt 2000 and &lt;br /&gt;                               xs:int(field[@name = 'year']/@value) lt 2011" &lt;br /&gt;                         xerces:message="A car's manufacture year must be between 2000 and 2011" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:assert test="count(field) = count(distinct-values(field/string(@name)))" &lt;br /&gt;                         xerces:message="None of the fields of an object 'car' can occur twice" /&amp;gt;&lt;/span&gt;&lt;br /&gt;           &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;        &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt; &lt;br /&gt; &lt;br /&gt;     &amp;lt;xs:complexType name="OBJECT_ON_SALE"&amp;gt;&lt;br /&gt;        &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;          &amp;lt;xs:extension base="OBJECT"&amp;gt;&lt;br /&gt;             &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="field/@name = ('price','currency')" &lt;br /&gt;                        xerces:message="An object that can be sold, must have the fields price/currency" /&amp;gt;&lt;br /&gt;             &amp;lt;xs:assert test="if (field/@name = 'price') then &lt;br /&gt;                              (field[@name = 'price']/xs:decimal(@value) gt 0 and&lt;br /&gt;                              field/@name = 'currency')&lt;br /&gt;                              else true()" &lt;br /&gt;                         xerces:message="If a field price is present, the currency field should exist. The value of price must be greater than 0." /&amp;gt;&lt;/span&gt;&lt;br /&gt;          &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;        &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt; &lt;br /&gt;     &amp;lt;xs:complexType name="OBJECT"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="field" minOccurs="0" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;            &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;               &amp;lt;xs:attribute name="name" type="xs:string" /&amp;gt;&lt;br /&gt;               &amp;lt;xs:attribute name="value" type="xs:string" /&amp;gt;&lt;br /&gt;            &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;/xs:element&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:attribute name="type" type="xs:string" /&amp;gt;    &lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The key design elements in the above schema document are the inheritance hierarchy and assertions/type-alternatives. The element "object" is validated by the schema type "CAR" or "BOOK". The set of assertions applicable on the type CAR/BOOK are the assertions on this type, as well as assertions inherited from the base types. The schema type applicable on the element "object" is controlled by the type-alternative switch (which works upon the value of attribute "type").&lt;br /&gt;&lt;br /&gt;When the XML document, [XML1] is validated (with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; 2.10.0 -- actually with the latest code-base on Xerces SVN as of today, because there was a minor bug [which affects this particular example] that got fixed few days after Xerces-J 2.10.0 got released) by the schema document [SCHEMA1] the validation succeeds (as there are no validation errors).&lt;br /&gt;&lt;br /&gt;Let's try to introduce some data errors in the XML instance document, and see what happens upon validation with the same schema document.&lt;br /&gt;&lt;br /&gt;Here's a modified XML instance document:&lt;br /&gt;&lt;i&gt;[XML3]&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;object type="car"&amp;gt;&lt;br /&gt;    &amp;lt;field name="price" value="-100" /&amp;gt;&lt;br /&gt;    &amp;lt;field name="currency" value="USD" /&amp;gt;&lt;br /&gt;    &amp;lt;field name="year" value="1999" /&amp;gt;&lt;br /&gt;  &amp;lt;/object&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;If the above XML document ([XML3] -- named "test.xml") is validated by the schema document, [SCHEMA1] we get following validation errors with Xerces-J:&lt;br /&gt;&lt;i&gt;[Error] test.xml:5:10: cvc-assertion.failure: Assertion failure. If a field price is present, the currency field should exist. The value of price must be greater than 0.&lt;br /&gt;[Error] test.xml:5:10: cvc-assertion.failure: Assertion failure. For a car the fields brand/year are required.&lt;br /&gt;[Error] test.xml:5:10: cvc-assertion.failure: Assertion failure. A car's manufacture year must be between 2000 and 2011.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;If we remove all of xerces:message attributes from assertions above, the following error messages are printed by Xerces for the above scenario:&lt;br /&gt;&lt;i&gt;[Error] test.xml:5:10: cvc-assertion.3.13.4.1: Assertion evaluation ('if (field/@name = 'price') then (field[@name = 'price']/xs:decimal(@value) gt 0 and field/@name = 'currency') else true()') for element 'object' with type 'OBJECT_ON_SALE' did not succeed.&lt;br /&gt;[Error] test.xml:5:10: cvc-assertion.3.13.4.1: Assertion evaluation ('field/@name = 'brand' and field/@name = 'year'') for element 'object' with type 'CAR' did not succeed.&lt;br /&gt;[Error] test.xml:5:10: cvc-assertion.3.13.4.1: Assertion evaluation ('xs:int(field[@name = 'year']/@value) gt 2000 and xs:int(field[@name = 'year']/@value) lt 2011') for element 'object' with type 'CAR' did not succeed&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;It's up-to the user's, that which error format is appropriate for them (the error format without xerces:message prints more error-context information. While the format with xerces:message could be useful to print user-friendly error messages, upon assertions failure).&lt;br /&gt;&lt;br /&gt;I won't describe in much detail now, the domain meaning of error messages above and the problem scenario itself. I believe, this fictitious problem domain is simple enough to understand these examples.&lt;br /&gt;&lt;br /&gt;I would end this post now. I'll take up the case of schema type "BOOK" in a future blog post (I imagine, the concepts I'm trying to illustrate here for the domain object CAR would be similar for the object BOOK).&lt;br /&gt;&lt;br /&gt;I'll try to write few more XSD 1.1 examples in subsequent posts!&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3701518897670714338?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3701518897670714338/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3701518897670714338' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3701518897670714338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3701518897670714338'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/07/xsd-11-schema-design-approaches-in-xsd.html' title='XSD 1.1: XML schema design approaches in XSD 1.1 world... PART 1'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6575797472351349841</id><published>2010-06-27T08:50:00.000+05:30</published><updated>2010-06-27T08:50:38.256+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: assertions failure error messages</title><content type='html'>Here's some info for &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; users!&lt;br /&gt;&lt;br /&gt;As refered on my earlier blog post (ref, &lt;a href="http://mukulgandhi.blogspot.com/2010/04/xsd-11-xsprecisiondecimal-assertions.html"&gt;http://mukulgandhi.blogspot.com/2010/04/xsd-11-xsprecisiondecimal-assertions.html&lt;/a&gt;), XSD 1.1 assertions error message was not a standard feature of the XML Schema language spec, and XML Schema WG was deliberating on this issue at that point of time.&lt;br /&gt;&lt;br /&gt;As of now, the XML Schema WG has taken a decision on this, which is as following (which is an response from David Ezell, XML Schema WG chair):&lt;br /&gt;&amp;lt;quote&amp;gt;&lt;br /&gt;The WG believes that this topic should be covered in a separate note describing best practices for how to handle this issue. &lt;a href="http://www.barefootliam.org/"&gt;Liam&lt;/a&gt; suggests following the i18n practice of publishing "articles" to recommend best practice.&lt;br /&gt;&lt;br /&gt;See http://www.w3.org/International/ for examples.&lt;br /&gt;&amp;lt;/quote&amp;gt;&lt;br /&gt;&lt;br /&gt;Therefore, keeping in view this observation from XML Schema WG, the &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; implementation would not change about assertions error messages. Or unless, there are any specific comments from Xerces users about assertions error reporting.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6575797472351349841?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6575797472351349841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6575797472351349841' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6575797472351349841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6575797472351349841'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/06/xsd-11-assertions-failure-error.html' title='XSD 1.1: assertions failure error messages'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7163624276117895899</id><published>2010-06-19T09:55:00.001+05:30</published><updated>2010-06-19T10:52:53.771+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J 2.10.0 released!</title><content type='html'>I'm pleased to extend the announcement of Xerces-J 2.10.0 release (released today. ref,&amp;nbsp;&lt;a href="http://markmail.org/message/m73xwkrmyacppu3l"&gt;http://markmail.org/message/m73xwkrmyacppu3l&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Xerces-J 2.10.0 is now available on the Xerces site, &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;http://xerces.apache.org/xerces2-j/&lt;/a&gt; to be used by community. This is a release after nearly two and a half years of the previous Xerces-J release, 2.9.1. This is a significant milestone at Xerces, with lot's of new features &amp;amp; bug fixes/enhancements.&lt;br /&gt;&lt;br /&gt;Xerces-J 2.10.0 provides two versions of the Xerces distributables:&lt;br /&gt;1. Xerces2 Java 2.10.0 - this is a maintainence release for 2.9.1 release (having bug fixes &amp;amp; enhancements), with essentially the same parsing &amp;amp; API support as 2.9.1 (except I think addition of support for&amp;nbsp;StAX 1.0 event API &amp;amp; Element Traversal API -- more details are available in Xerces release notes).&lt;br /&gt;2. Xerces2 Java 2.10.0 (XML Schema 1.1) (Beta) - this release supports a partial experimental implementation of the &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; 1.1 Structures and Datatypes Working Drafts (December 2009), along with all the changes available in "Xerces2 Java 2.10.0" release (point 1).&lt;br /&gt;&lt;br /&gt;PS: I would also like to extend special thanks to the&amp;nbsp;&lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;Eclipse/PsychoPath XPath 2.0&lt;/a&gt; team members, &lt;a href="http://intellectualcramps.blogspot.com/"&gt;Dave Carver&lt;/a&gt; &amp;amp; &lt;a href="http://www.selskabet.org/"&gt;Jesper S Møller&lt;/a&gt; for helping producing an excellent XPath 2.0 engine, which underlies Xerces XML Schema 1.1 assertions and type-alternatives implementation. Special thanks also to&amp;nbsp;Andrea Bittau, who originally authored the PsychoPath engine.&lt;br /&gt;&lt;br /&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;I hope the community likes the Xerces 2.10.0 release!&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;Please feel free to discuss about Xerces-J at:&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;a href="http://xerces.apache.org/mail.html#xerces-j-user"&gt;http://xerces.apache.org/mail.html#xerces-j-user&lt;/a&gt;&lt;/div&gt;&lt;div style="margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px;"&gt;&lt;a href="http://xerces.apache.org/mail.html#xerces-j-dev"&gt;http://xerces.apache.org/mail.html#xerces-j-dev&lt;/a&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7163624276117895899?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7163624276117895899/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7163624276117895899' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7163624276117895899'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7163624276117895899'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/06/xerces-j-2100-released.html' title='Xerces-J 2.10.0 released!'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1658069508106985468</id><published>2010-05-27T06:35:00.004+05:30</published><updated>2010-05-30T07:12:23.667+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: schema versioning, and Xerces-J support</title><content type='html'>&lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; 1.1 provides a nice schema composition feature, called &lt;a href="http://www.w3.org/TR/xmlschema11-1/#cip"&gt;"Conditional inclusion"&lt;/a&gt;&amp;nbsp;which allows us to include/exclude Schema components, during schema processing, based on values of certain special control&amp;nbsp;attributes (minVersion &amp;amp; maxVersion),&amp;nbsp;specified on the schema components.&lt;br /&gt;&lt;br /&gt;Here are two simplistic examples, illustrating this feature:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Example 1&lt;/b&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;XML document [1]:&lt;/i&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;test&amp;gt;3&amp;lt;/test&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;XSD 1.1 document [2]:&lt;/i&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="Apple-style-span" style="color: orange;"&gt;xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:element name="test"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:restriction base="xs:positiveInteger"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assertion test="$value mod 2 = 0" vc:minVersion="1.1" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;/xs:schema&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the above schema document [2], the attribute vc:minVersion on &lt;a href="http://www.w3.org/TR/xmlschema11-2/#rf-assertions"&gt;xs:assertion&lt;/a&gt; instruction specifies, that the assertion instruction would only be&amp;nbsp;processable&amp;nbsp;by XSD processors, which support 1.1 and a higher level of the XSD schema language. If this schema document [2] is run by an XSD 1.1 (and possible a higher language version in future) processor in XSD 1.0 mode, the assertion instruction would be ignored by the XSD engine. The schema versioning features allows us to have a XSD engine, ignore certain schema components (in entirety along with their descendant instructions).&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Example 2&lt;/b&gt;&lt;span class="Apple-style-span" style="font-style: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;&lt;i&gt;XML document [3]:&lt;/i&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;address ver="V2"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;street1&amp;gt;&amp;lt;/street1&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;street2&amp;gt;XX&amp;lt;/street2&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;city&amp;gt;XX&amp;lt;/city&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;state&amp;gt;XX&amp;lt;/state&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;country&amp;gt;XX&amp;lt;/country&amp;gt;&lt;br /&gt;&amp;lt;/address&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;XSD 1.1 document [4]:&lt;/i&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="Apple-style-span" style="color: orange;"&gt;xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;xs:element name="address" type="Address"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:alternative test="@ver = 'V2'" type="AddressV2" vc:minVersion="1.1" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;xs:complexType name="Address"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:element name="street1" type="xs:string" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:element name="street2" type="xs:string" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:element name="city" type="xs:string" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:element name="state" type="xs:string" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:element name="country" type="xs:string" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;xs:complexType name="AddressV2"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;xs:extension base="Address"&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;xs:attribute name="ver" type="xs:string" /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="not(normalize-space(street1) = '')" /&amp;gt;&lt;/span&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: small;"&gt;&amp;lt;/xs:schema&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Similarly, the above schema document ([4]) ignores the &lt;a href="http://www.w3.org/TR/xmlschema11-1/#cTypeAlternative"&gt;type-alternative&lt;/a&gt; instruction, if the XSD 1.1 processor is run in a XSD 1.0 mode. I believe, the intent of the above schema and the XML document should be clear enough (we are using an "address" element in XML document, which needs to be validated by a corresponding XML Schema type. The complex type, "AddressV2" extends the type "Address", and has an assertion specification to constrain the contents of the element "street1" -- in this particular example, the assertion on type "AddressV2" constrains the element, "street1" to have some&amp;nbsp;significant&amp;nbsp;white-space characters).&lt;br /&gt;&lt;br /&gt;&lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;&amp;nbsp;runs these examples fine.&lt;br /&gt;&lt;br /&gt;Summarizing this post: The XSD 1.1 schema versioning features, allows us to write a XSD schema containing mix and match of XSD 1.0 and 1.1 instructions (and XSD instructions beyond XSD 1.1 level, for future!), and have the XSD 1.1 engine ignore certain XSD instructions at run-time depending, at which XSD language level, the XSD 1.1 engine was invoked.&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1658069508106985468?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1658069508106985468/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1658069508106985468' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1658069508106985468'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1658069508106985468'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/05/xsd-11-schema-versioning-and-xerces-j.html' title='XSD 1.1: schema versioning, and Xerces-J support'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5920353324209287773</id><published>2010-04-25T21:41:00.004+05:30</published><updated>2010-08-05T22:13:30.718+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: negative "pattern" facets and assertions</title><content type='html'>While exploring more of &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 assertions, I've been pretty convinced that much of the limitations of XSD "pattern" facet can be overcome with assertions (and of-course one of real benefits of XSD 1.1 assertions is the ability to specify co-occurrence constraints, in XML Schema documents -- here's a nice &lt;a href="http://www.ibm.com/developerworks/library/x-xml11pt2/"&gt;article explaining XML Schema 1.1 co-occurrence constraints&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;I think, one of the things which might get quite difficult to express in XML Schema 1.0, is specifying a negative word list.&lt;br /&gt;&lt;br /&gt;For example, if we have this simple XML document:&lt;br /&gt;&lt;pre&gt;  &amp;lt;fruit&amp;gt;apple&amp;lt;/fruit&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And we want that, the XML element "fruit" must not contain say the words "cherry" or "guava". Although, this looks a pretty straight-forward regex use-case, but unfortunately it might get quite cumbersome to express this seemingly straightforward regex pattern, with the available XSD 1.0 regular-expression syntax.&lt;br /&gt;&lt;br /&gt;My quick try to express this with XSD 1.0, was something like following:&lt;br /&gt;&amp;lt;xs:pattern value="^(cherry|guava)" /&amp;gt;&lt;br /&gt;&lt;br /&gt;But unfortunately, the above pattern facet and quite a few similar regexes, can't accomplish this seemingly common use-case easily (I think, this is doable with XSD 1.0 regex's but certainly, it would be quite tedious to come to the right regex pattern -- of-course regex experts/gurus could do this easily, but not me at this moment!).&lt;br /&gt;&lt;br /&gt;And now, I try to express these validation constraints with XSD 1.1 assertions. Here's a sample XSD 1.1 schema [1], using assertions to solve this, and few of similar use-cases:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;     &amp;lt;xs:element name="Example" type="Fruits1" /&amp;gt;&lt;br /&gt;  &lt;br /&gt;     &amp;lt;xs:complexType name="Fruits1"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="fruit" type="xs:string" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="exclude" type="xs:string" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="not(fruit = tokenize(exclude,','))" /&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;     &amp;lt;xs:complexType name="Fruits2"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="fruit" type="xs:string" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="exclude" type="xs:string" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="not(fruit = (for $x in tokenize(exclude,',') return &lt;br /&gt;                                              normalize-space($x)))" /&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;     &amp;lt;xs:complexType name="Fruits3"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="fruit" type="xs:string" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="exclude" type="xs:string" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="not(fruit = (for $x in tokenize(exclude,',') return &lt;br /&gt;                                (string-join(tokenize($x,' '),''))))" /&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;   &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;A sample XML instance document [2], that we'll validate with the above schema, is following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example&amp;gt;&lt;br /&gt;    &amp;lt;fruit&amp;gt;apple&amp;lt;/fruit&amp;gt;&lt;br /&gt;    &amp;lt;exclude&amp;gt;cherry,guava&amp;lt;/exclude&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As stated in the original requirements above, we want that the word in element "fruit" must not contain any of words, from the comma-separated list in the "exclude" element.&lt;br /&gt;&lt;br /&gt;In the above XSD schema [1], the complex type "Fruits1" can successfully validate the above XML instance document [2].&lt;br /&gt;&lt;br /&gt;The complex type "Fruits2" can validate an exclude list, where there could be white-spaces before and after the 'comma separator'. For example, the list "cherry, guava" (please note, an extra white-space after the 'comma') would be considered an appropriate exclusion list for this example. Whereas, this list variant cannot be validated by the schema type, "Fruits1".&lt;br /&gt;&lt;br /&gt;And the complex type "Fruits3" can validate an exclude list of kind, "cherry, g u a v a" (i.e, there could be white-space characters, within a word) -- this is a figment of my imagination :). But certainly there could possibly be such lexical constraints in instance documents.&lt;br /&gt;&lt;br /&gt;PS: All the examples in this post were tested with, &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I hope, that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5920353324209287773?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5920353324209287773/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5920353324209287773' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5920353324209287773'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5920353324209287773'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/04/xsd-11-negative-pattern-facets-and.html' title='XSD 1.1: negative &quot;pattern&quot; facets and assertions'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3699864605259530638</id><published>2010-04-17T09:33:00.012+05:30</published><updated>2010-06-27T08:28:08.614+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: xs:precisionDecimal, assertions and Xerces-J updates</title><content type='html'>&lt;i&gt;Section 1&lt;/i&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Recently, I went through in sufficient detail about the XSD primitive data-type, &lt;a href="http://www.w3.org/TR/xmlschema11-2/#precisionDecimal"&gt;xs:precisionDecimal&lt;/a&gt; (newly introduced in, &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1), and was trying to use XSD 1.1 assertions to simulate xs:precisionDecimal (just to vent my curiosity and exploring more of, XSD assertions) as a user-defined (as a restriction of &lt;a href="http://www.w3.org/TR/xmlschema11-2/#decimal"&gt;xs:decimal&lt;/a&gt; data-type) XSD Simple Type (though I believe, a native implementation of xs:precisionDecimal should also exist in an XSD 1.1 implementation, or in language systems which may use the XSD type system -- for example, a stand-alone XPath (2.x) implementation which uses an XSD type system).&lt;/div&gt;&lt;br /&gt;Here's an XSD 1.1 schema example, illustrating these concepts:&lt;br /&gt;[1]&lt;br /&gt;&lt;pre&gt;   &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;      &amp;lt;xs:element name="example" type="myPrecisionDecimal" /&amp;gt;&lt;br /&gt;  &lt;br /&gt;      &amp;lt;xs:simpleType name="myPrecisionDecimal"&amp;gt;&lt;br /&gt;        &amp;lt;xs:restriction base="xs:decimal" xmlns:xerces="http://xerces.apache.org"&amp;gt;&lt;br /&gt;           &amp;lt;xs:totalDigits value="6" /&amp;gt;&lt;br /&gt;           &amp;lt;xs:fractionDigits value="4" /&amp;gt;&lt;br /&gt;           &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assertion test="string-length(substring-after(string($value), '.')) ge 2" &lt;br /&gt;                  xerces:message="minScale of this decimal number should be 2" /&amp;gt;&lt;/span&gt;&lt;br /&gt;        &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;  &lt;br /&gt;   &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The XSD type, "myPrecisionDecimal" defined above has following correspondences with the type, xs:decimal:&lt;br /&gt;a) The facet specification, xs:totalDigits in "myPrecisionDecimal" is equivalent to the facet xs:totalDigits in xs:decimal.&lt;br /&gt;b) The facet specification, xs:fractionDigits in "myPrecisionDecimal" is equivalent to the facet "maxScale" for, xs:decimal.&lt;br /&gt;c) The assertion facet in, "myPrecisionDecimal" is equivalent (an user-defined attempt to equalize!) to the facet "minScale" for, xs:decimal.&lt;br /&gt;&lt;br /&gt;When the above schema document [1], is used to validate the following XML instance:&lt;br /&gt;&lt;pre&gt;&amp;lt;example&amp;gt;44.4&amp;lt;/example&amp;gt;&lt;br /&gt;&lt;/pre&gt;The following error message is produced:&lt;br /&gt;&lt;i&gt;[Error] test.xml:1:24: cvc-assertion.failure: Assertion failure. minScale of this decimal number should be 2.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;It's also worth noting that, the above user-defined type "myPrecisionDecimal" cannot be considered a true equivalent of XSD type, xs:precisionDecimal as defined in XSD 1.1 spec, because xs:precisionDecimal also includes values for positive and negative infinity and for "not a number", and it differentiates between "positive zero" and "negative zero" (these aspects, are not defined for xs:decimal). The above example, for "myPrecisionDecimal" only demostrates, simulating the "minScale" facet (which is not available in the type, xs:decimal) of xs:precisionDecimal.    &lt;/div&gt;&lt;br /&gt;&lt;i&gt;Section 2&lt;/i&gt;&lt;br /&gt;(&lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;, assertions implementation update)&lt;br /&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Xerces-J recently implemented, an extension attribute "message" (specified in a namespace, http://xerces.apache.org, for Xerces-J XSD 1.1 implementation) on XSD 1.1 assertion instructions. The value of this attribute, needs to be an error message that will be reported by an XSD 1.1 engine upon assertions failure.&lt;/div&gt;&lt;br /&gt;An example of this is illustrated, in the schema document above [1].&lt;br /&gt;&lt;br /&gt;In the absence of the "message" attribute on assertions (or if it's present, but it doesn't contain any significant non-whitespace characters), the following default error message is produced by Xerces:&lt;br /&gt;&lt;i&gt;[Error] test.xml:1:24: cvc-assertion.3.13.4.1: Assertion evaluation ('string-l&lt;br /&gt;ength(substring-after(string($value), '.')) ge 2') for element 'example' with type 'myPrecisionDecimal' did not succeed.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;We could see the benefit of, the "message" attribute on assertions, which to my opinion are following:&lt;br /&gt;a) For complex (&amp;amp; particularly, lengthy) XPath expressions in assertions, the default error messages produced by Xerces, could be quite verbose which the user's may not find convenient to view &amp;amp; debug. The user experience, with default assertions error messages, may be further trouble-some if there are numerous assertion evaluations for XML documents -- we could imagine the user-experience, for say &lt;b&gt;maxOccurs="unbounded"&lt;/b&gt; specification on XML elements on which assertions apply OR let's say, there may be of the order of "&amp;gt; 10" different assertions.&lt;br /&gt;b) We could specify, domain specific error messages with the assertions "message" attribute.&lt;br /&gt;&lt;br /&gt;Though, the advantage of the default assertion error messages produced by Xerces is that, it prints to the user, the name of XSD type and the element/attribute involved in a particular assertions validation episode.&lt;br /&gt;&lt;br /&gt;PS: There's been a recent issue raised with the XSD WG, which proposes addition of a "message" attribute on assertions in the XSD 1.1 language itself. The Xerces implementation of assertions "message" attribute may change in future, depending on a recommendation related to this, from the XSD WG.&lt;br /&gt;&lt;br /&gt;I hope, that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3699864605259530638?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3699864605259530638/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3699864605259530638' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3699864605259530638'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3699864605259530638'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/04/xsd-11-xsprecisiondecimal-assertions.html' title='XSD 1.1: xs:precisionDecimal, assertions and Xerces-J updates'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5186594638827374570</id><published>2010-03-21T19:50:00.001+05:30</published><updated>2010-03-21T19:56:51.125+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>playing again with XSD 1.1 assertions</title><content type='html'>Some time ago, XSLT folks (including me!) were discussing on &lt;a href="http://www.mulberrytech.com/xsl/xsl-list/"&gt;XSL-List&lt;/a&gt; the design of an XML schema, describing a product catalog. This post has nothing to do with XSLT, except that an earlier discussion on XSL-List enkindled me with yet another XSD schema use-case, to try out the &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 assertions implementation. I wrote the following XSD 1.1 schema use-case, with a desire to find out if Xerces-J XSD 1.1 assertion implementation would succeed, for this example (and to cause no surprise to readers, I'm pleased to say, that Xerces passes this example!).&lt;br /&gt;&lt;br /&gt;So here goes this example.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;XML document:&lt;/i&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version="1.0" encoding="UTF-8" ?&amp;gt;&lt;br /&gt;  &amp;lt;product id="100"&amp;gt;&lt;br /&gt;    &amp;lt;shortname&amp;gt;Sun Press, Java Book&amp;lt;/shortname&amp;gt;&lt;br /&gt;    &amp;lt;description&amp;gt;Java Language: Design and Programming&amp;lt;/description&amp;gt;&lt;br /&gt;    &amp;lt;author&amp;gt;James Gosling&amp;lt;/author&amp;gt;&lt;br /&gt;    &amp;lt;price&amp;gt;&lt;br /&gt;      &amp;lt;value effective="2000-10-10" format="hard cover"&amp;gt;25&amp;lt;/value&amp;gt;&lt;br /&gt;      &amp;lt;value effective="2005-10-10" format="hard cover"&amp;gt;20&amp;lt;/value&amp;gt;&lt;br /&gt;      &amp;lt;value effective="2009-10-10" format="pdf" freeware="true"&amp;gt;0&amp;lt;/value&amp;gt;&lt;br /&gt;    &amp;lt;/price&amp;gt;&lt;br /&gt;  &amp;lt;/product&amp;gt;&lt;br /&gt;&lt;/pre&gt;An &lt;i&gt;XSD 1.1 schema&lt;/i&gt; validating the above XML document:&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version="1.0" encoding="UTF-8" ?&amp;gt;&lt;br /&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;xs:complexType name="Product"&amp;gt;&lt;br /&gt;     &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:element name="shortName"&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;           &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;             &amp;lt;xs:maxLength value="20"/&amp;gt;&lt;br /&gt;           &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;       &amp;lt;/xs:element&amp;gt;&lt;br /&gt;       &amp;lt;xs:element name="description" type="xs:string"/&amp;gt;&lt;br /&gt;       &amp;lt;xs:element name="author" type="xs:string"/&amp;gt;&lt;br /&gt;       &amp;lt;xs:element name="price"&amp;gt;&lt;br /&gt;         &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;           &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element name="value" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;                &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;                  &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;                    &amp;lt;xs:extension base="xs:double"&amp;gt;&lt;br /&gt;                      &amp;lt;xs:attribute name="effective" type="xs:date" use="required"/&amp;gt;&lt;br /&gt;                      &amp;lt;xs:attribute name="freeware" type="xs:boolean"/&amp;gt;&lt;br /&gt;                      &amp;lt;xs:attribute name="format" use="required"&amp;gt;&lt;br /&gt;                        &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;                          &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;                            &amp;lt;xs:enumeration value="hard cover"/&amp;gt;&lt;br /&gt;                            &amp;lt;xs:enumeration value="pdf"/&amp;gt;&lt;br /&gt;                          &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;                        &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;                      &amp;lt;/xs:attribute&amp;gt;&lt;br /&gt;                      &lt;span style="color: orange;"&gt;&amp;lt;xs:assert test="@effective lt current-date()" /&amp;gt;&lt;br /&gt;                      &amp;lt;xs:assert test="if (@freeware eq true()) then (@format eq 'pdf' and . eq 0)&lt;br /&gt;                                       else true()" /&amp;gt;&lt;/span&gt;                    &lt;br /&gt;                    &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;                  &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;                &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;             &amp;lt;/xs:element&amp;gt;&lt;br /&gt;           &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;           &lt;span style="color: orange;"&gt;&amp;lt;xs:assert test="every $vl in value[position() lt last()] satisfies&lt;/span&gt;&lt;br /&gt;&lt;span style="color: orange;"&gt;                            ($vl gt $vl/following-sibling::value[1]) and &lt;/span&gt;&lt;br /&gt;&lt;span style="color: orange;"&gt;                            ($vl/@effective lt $vl/following-sibling::value[1]/@effective)" /&amp;gt;&lt;/span&gt;&lt;br /&gt;         &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;       &amp;lt;/xs:element&amp;gt;&lt;br /&gt;     &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;xs:attribute name="ID" type="xs:positiveInteger" use="required"/&amp;gt;&lt;br /&gt;   &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xs:element name="product" type="Product"/&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I don't wish to explain in detail the problem domain behind the above XML &amp; XSD documents (I believe, readers familiar with XSD language &amp; XML could easily understand the intent of the above example). In very shortest description, this example "illustrates a simple product catalog, describing a single product".&lt;br /&gt;Here's a short explanation, about what the assertions -- highlighted with a different color (starting from assertion at top, to assertion at bottom) in above schema document are, intending to do:&lt;br /&gt;1. The first assertion is checking, that the value of attribute "effective" (with a schema type, xs:date) is prior to today's date.&lt;br /&gt;2. The second assertion is checking, that if value of attribute "freeware" is a boolean 'true', then value of attribute "format" must be 'pdf' &amp; the numeric value of price should be 0.&lt;br /&gt;3. The third assertion is checking, that price always reduces in future, &amp; the effective date of the price is prior to the next price revision.&lt;br /&gt;&lt;br /&gt;I enjoyed writing this example, and I'm glad that this worked with Xerces. The &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;Eclipse/PsychoPath XPath 2.0 implementation&lt;/a&gt; (which is the underlying XPath 2 implementation, used by Xerces-J XSD 1.1 assertions implementation) also looks pretty compliant to the XPath 2 language.&lt;br /&gt;&lt;br /&gt;I hope, that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5186594638827374570?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5186594638827374570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5186594638827374570' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5186594638827374570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5186594638827374570'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/03/playing-again-with-xsd-11-assertions.html' title='playing again with XSD 1.1 assertions'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2446982094887838417</id><published>2010-03-07T07:52:00.001+05:30</published><updated>2010-03-07T13:20:32.220+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XSModel serialization</title><content type='html'>There's a new API sample contributed to the &lt;a href="http://xerces.apache.org/xerces2-j"&gt;Xerces-J&lt;/a&gt; code-base (in the schema-dev XSD 1.1, branch), which allows us to serialize a &lt;a href="http://xerces.apache.org/xerces2-j/javadocs/xs/org/apache/xerces/xs/XSModel.html"&gt;Xerces-J XSModel&lt;/a&gt;. This should be available in the upcoming Xerces-J release, 2.10.0.&lt;br /&gt;&lt;br /&gt;This could be invoked by using the Java class, xs.XSSerializer.&lt;br /&gt;&lt;br /&gt;Here's one of the use-case for this, as asked by colleagues in the community:&lt;br /&gt;&lt;a href="http://mail-archives.apache.org/mod_mbox/xerces-j-users/200611.mbox/%3c4557B05A.6000808@gael.fr%3e"&gt;http://mail-archives.apache.org/mod_mbox/xerces-j-users/200611.mbox/%3c4557B05A.6000808@gael.fr%3e&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2446982094887838417?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2446982094887838417/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2446982094887838417' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2446982094887838417'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2446982094887838417'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/03/xerces-j-xsmodel-serialization.html' title='Xerces-J: XSModel serialization'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-105638801719025709</id><published>2010-02-24T21:59:00.007+05:30</published><updated>2010-03-07T09:45:11.885+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: some more assertions fun</title><content type='html'>Here are some more &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 assertions examples (interesting one's I guess), that I tried running with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; XSD 1.1 implementation (these ones run fine, with Xerces!):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 1&lt;/i&gt; [1]:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="test" type="X" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:complexType name="X"&amp;gt;&lt;br /&gt;      &amp;lt;xs:group ref="List1" /&amp;gt;&lt;br /&gt;      &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="a and b and d" /&amp;gt;&lt;/span&gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:complexType name="Y"&amp;gt;&lt;br /&gt;      &amp;lt;xs:group ref="List1" /&amp;gt;&lt;br /&gt;      &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="a and b and c and d" /&amp;gt;&lt;/span&gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;    &amp;lt;xs:group name="List1"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="a" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="b" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="c" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="d" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;    &amp;lt;/xs:group&amp;gt;&lt;br /&gt;           &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The corresponding XML instance, document is:&lt;br /&gt;&lt;pre&gt;&amp;lt;test&amp;gt;&lt;br /&gt;    &amp;lt;a&amp;gt;hello&amp;lt;/a&amp;gt;&lt;br /&gt;    &amp;lt;b&amp;gt;world&amp;lt;/b&amp;gt;&lt;br /&gt;    &amp;lt;!--&amp;lt;c&amp;gt;hello..&amp;lt;/c&amp;gt;--&amp;gt;&lt;br /&gt;    &amp;lt;d&amp;gt;world..&amp;lt;/d&amp;gt;&lt;br /&gt;  &amp;lt;/test&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here's the rationale/goal, that motived me to write this XSD sample:&lt;br /&gt;I wanted to define a pair of XSD complex types (something like, X &amp;amp; Y above), such that one of the types could reuse the element particles, from the other type. If this problem could have been solved with XSD type derivation (which I attempted initially), I wanted that only one of the elements in the derived type could become optional -- element, "c" in this example (i.e, with minOccurs = 0 &amp;amp; maxOccurs = 1), while the other elements from the base type should have the same occurrence indicator (i.e, a mandatory indicator -- which is, minOccurs = maxOccurs = 1).&lt;br /&gt;&lt;br /&gt;Interestingly, this problem is unsolvable with XSD type derivation (either complex type extension, or restriction mechanism).&lt;br /&gt;&lt;br /&gt;For this schema use-case, I came up with the XSD sample above [1], which meets my goal to be able to re-use the element particles in the XSD types. The Schema above [1], defines a global group which contains a sequence of XML element definitions. All of the elements in the group, are marked as optional. Within the complex types (X &amp;amp; Y), the cardinality of elements (0-1 or 1-1) is enforced with XSD assertions. Defining all elements in the group, as optional allows us to reuse this list in different XSD types easily, as we can constrain the elements (say controlling the cardinality of elements, or even the contents of elements/attributes) in different contexts/types say using, assertions.&lt;br /&gt;&lt;br /&gt;Using the above schema example [1], therefore if one wants to use a XSD type, where element "c" is optional, one would use the type, "X". While if, one wants to use a XSD type, where all elements are mandatory, one would use the type, "Y".&lt;br /&gt;&lt;br /&gt;After having solved the use-case I had in mind (explained above), so just for fun, I wrote another schema using some more assertions.&lt;br /&gt;&lt;br /&gt;Here's the 2nd XSD schema:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 2&lt;/i&gt; [2]:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;     &amp;lt;xs:element name="test" type="X" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:complexType name="X"&amp;gt;&lt;br /&gt;       &amp;lt;xs:group ref="List1" /&amp;gt;&lt;br /&gt;       &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="a and b and d" /&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:complexType name="Y"&amp;gt;&lt;br /&gt;       &amp;lt;xs:group ref="List1" /&amp;gt;&lt;br /&gt;       &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="a and b and c and d" /&amp;gt;&lt;/span&gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:group name="List1"&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="a" minOccurs="0"&amp;gt;&lt;br /&gt;             &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;               &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;                 &amp;lt;xs:element name="a1" type="xs:string" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;               &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;               &amp;lt;xs:attribute name="aCount" type="xs:nonNegativeInteger" /&amp;gt;&lt;br /&gt;               &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="count(a1) eq @aCount" /&amp;gt;&lt;/span&gt;&lt;br /&gt;             &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;           &amp;lt;/xs:element&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="b" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="c" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="d" type="xs:string" minOccurs="0"/&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;/xs:group&amp;gt;&lt;br /&gt;           &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The schema [2] is conceptually similar, to schema [1]. The only difference between the two schemas is, that in schema [2], element "a" has complex content, while in schema [1], element "a" is defined to have simple content (which is, xs:string). In schema, [2]'s complex type we define another assertion (which enforces the constraint that, value of attribute "aCount" is equal to the number of, "a1" children of element, "a"). The assertion definition in the complex type of element, "a" in the 2nd schema, is written only to visually increase the complexity of the element a's definition (of-course, this also does increase the functional complexity of element, "a" and subsequently the complexity of contents of the global group definition, in the 2nd schema).&lt;br /&gt;&lt;br /&gt;The 2nd schema illustrates, that a more functionally complex list of particles (a, b, c &amp;amp; d here) get more benefit by the schema component re-use technique (accomplished with a XSD group, and assertions) illustrated in this post.&lt;br /&gt;&lt;br /&gt;I hope, that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-105638801719025709?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/105638801719025709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=105638801719025709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/105638801719025709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/105638801719025709'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/02/xsd-11-some-more-assertions-fun.html' title='XSD 1.1: some more assertions fun'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7866703428408432964</id><published>2010-02-14T20:57:00.007+05:30</published><updated>2010-03-07T09:45:11.886+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J, XSD 1.1 assertions: complexType -&gt; simpleContent -&gt; restriction</title><content type='html'>XSD 1.1 complex types are specified by the grammar given here, in the XSD 1.1 spec:&lt;br /&gt;&lt;a href="http://www.w3.org/TR/xmlschema11-1/#declare-type"&gt;http://www.w3.org/TR/xmlschema11-1/#declare-type&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;XSD complex type definitions are essentially composed of three mutually exclusive definitions, as follows:&lt;br /&gt;&lt;pre&gt;  &amp;lt;complexType ...&lt;br /&gt;    &lt;span style="color: red;"&gt;simpleContent&lt;/span&gt; |&lt;br /&gt;    &lt;span style="color: lime;"&gt;complexContent&lt;/span&gt; |&lt;br /&gt;    &lt;span style="color: blue;"&gt;openContent?, (group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?), assert*))&lt;/span&gt;&lt;br /&gt;  &amp;lt;/complexType&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The assertions specification in complexType -&amp;gt; simpleContent -&amp;gt; restriction is a bit different, that all other assertions cases on complex types (as this consists of assertion facets, as well as/or assertions on the complex type).&lt;br /&gt;&lt;br /&gt;This is specified by the following XSD 1.1 grammar:&lt;br /&gt;&lt;pre&gt;  &amp;lt;simpleContent&lt;br /&gt;    id = ID&lt;br /&gt;    {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;    Content: (annotation?, (restriction | extension))&lt;br /&gt;  &amp;lt;/simpleContent&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;restriction&lt;br /&gt;    base = QName&lt;br /&gt;    id = ID&lt;br /&gt;    {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;    Content: (annotation?, (simpleType?, (minExclusive | minInclusive | maxExclusive | maxInclusive | totalDigits | fractionDigits | maxScale | minScale | length | minLength | maxLength | enumeration | whiteSpace | pattern | &lt;b&gt;assertion&lt;/b&gt; | {any with namespace: ##other})*)?, ((attribute | attributeGroup)*, anyAttribute?), &lt;b&gt;assert&lt;/b&gt;*)&lt;br /&gt;  &amp;lt;/restriction&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The XSD definition for xs:restriction above specifies assertions something like following:&lt;br /&gt;&lt;i&gt;assertion*, ..., assert*&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Here, &lt;b&gt;xs:assertion&lt;/b&gt; (with cardinality, 0-n) is a facet for the simple type value (specified by, complexType -&gt; simpleContent). Whereas, &lt;b&gt;xs:assert&lt;/b&gt; (with cardinality, 0-n) is an assertion definition on the complex type (which has access to the element tree, like the XML element itself, and it's attributes if there are any). xs:assertion definitions on, complexType -&gt; simpleContent -&gt; restriction do not have access to the element tree (on which the complex type is applicable), and can only access the simple type value (using, the implicit assertion variable  &lt;b&gt;$value&lt;/b&gt;, having a XSD type specified by the definition, &amp;lt;xs:restriction base = &lt;b&gt;QName&lt;/b&gt; ...) of the element in the context.&lt;br /&gt;&lt;br /&gt;Here's a small fictitious examples, illustrating these concepts:&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;A a="15"&amp;gt;Example A&amp;lt;/A&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1, Schema [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="A"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;          &amp;lt;xs:restriction base="myBase"&amp;gt;    &lt;br /&gt;            &amp;lt;&lt;b&gt;xs:assertion&lt;/b&gt; test="contains($value, 'Example')" /&amp;gt;&lt;br /&gt;            &amp;lt;&lt;b&gt;xs:assert&lt;/b&gt; test="@a mod 5 = 0" /&amp;gt;    &lt;br /&gt;          &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;        &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:complexType name="myBase"&amp;gt;&lt;br /&gt;      &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;         &amp;lt;xs:extension base="xs:string"&amp;gt; &lt;br /&gt;           &amp;lt;xs:attribute name="a" type="xs:int" /&amp;gt;  &lt;br /&gt;         &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleContent&amp;gt; &lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the Schema above [2], there are two assertions (shown with bold emphasis) specified on the XSD type. One of assertions is a facet for the simple content, and the other is an assertion on the complex type.&lt;br /&gt;&lt;br /&gt;I believe, the above Schema is simple enough and self-explanatory, to illustrate the points I've tried to explain in this post.&lt;br /&gt;&lt;br /&gt;Actually, what prompted me to write this post, was that there was a minor bug in &lt;b&gt;complexType -&gt; simpleContent -&gt; restriction&lt;/b&gt; facet processing in &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; XSD 1.1 SVN code, which we could fix today, and the fix is now available in Xerces-J SVN repository.&lt;br /&gt;&lt;br /&gt;Interestingly, this fix was there in Xerces-J SVN during some past Xerces SVN version. But going forward with assertions development, this bug got introduced, and now has been fixed again.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7866703428408432964?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7866703428408432964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7866703428408432964' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7866703428408432964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7866703428408432964'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/02/xerces-j-xsd-11-assertions-complextype.html' title='Xerces-J, XSD 1.1 assertions: complexType -&gt; simpleContent -&gt; restriction'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8500295598253265687</id><published>2010-02-06T10:13:00.002+05:30</published><updated>2010-03-07T09:32:22.306+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>PsychoPath XPath2 processor update: fn:name() function fix</title><content type='html'>While writing following blog post, &lt;a href="http://mukulgandhi.blogspot.com/2010/01/xsd-11-wild-cards-in-compositor-and.html"&gt;http://mukulgandhi.blogspot.com/2010/01/xsd-11-wild-cards-in-compositor-and.html&lt;/a&gt; (dated, Jan 31, 2010) [1], I actually unearthed a bug in &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;PsychoPath XPath 2 processor&lt;/a&gt;, whereby the XPath2 fn:name() function didn't evaluate properly with zero arity (it raised a "context undefined" exception, even if a context item existed).&lt;br /&gt;&lt;br /&gt;This bug led me to use the, fn:local-name() (whose implementation was correct) function instead, for the above mentioned blog post [1].&lt;br /&gt;&lt;br /&gt;The good news is, that now this bug with fn:name() function is fixed (ref, &lt;a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=301539"&gt;https://bugs.eclipse.org/bugs/show_bug.cgi?id=301539&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;For the example given in the blog post [1], the given XSD 1.1 assertion could now be written like following, as well:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:assert test="(*[1]/name() = ('fname', 'lname')) and &lt;br /&gt;                 (*[2]/name() = ('fname', 'lname'))" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;(instead, of the "local-name" function as used in the mentioned blog post [1])&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8500295598253265687?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8500295598253265687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8500295598253265687' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8500295598253265687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8500295598253265687'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/02/psychopath-xpath2-processor-update.html' title='PsychoPath XPath2 processor update: fn:name() function fix'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5628181368605285150</id><published>2010-02-05T21:41:00.001+05:30</published><updated>2010-02-05T21:42:25.491+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><title type='text'>C. M. Sperberg-McQueen: slides about XSD 1.1</title><content type='html'>I just came across this brief (but sufficient enough to give a good overview) slide presentation about &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema (XSD)&lt;/a&gt; 1.1, by C. M. Sperberg-McQueen:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.blackmesatech.com/2009/07/xsd11/"&gt;http://www.blackmesatech.com/2009/07/xsd11/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Nice ones indeed, and highly recommended.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5628181368605285150?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5628181368605285150/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5628181368605285150' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5628181368605285150'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5628181368605285150'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/02/c-m-sperberg-mcqueen-slides-about-xsd.html' title='C. M. Sperberg-McQueen: slides about XSD 1.1'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1747995359108743979</id><published>2010-01-31T16:15:00.005+05:30</published><updated>2010-03-07T09:45:11.887+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: wild-cards in xs:all compositor, and assertions</title><content type='html'>I was reading through the latest &lt;a href="http://www.w3.org/TR/xmlschema11-1/"&gt;XSD 1.1&lt;/a&gt; language draft, and one of the things that has changed between XSD 1.0 and 1.1, are some of the details of, xs:all compositor instruction.&lt;br /&gt;&lt;br /&gt;XSD 1.1 defines &amp;lt;xs:all ..&amp;gt; compositor as follows:&lt;br /&gt;&lt;pre&gt;  &amp;lt;all&lt;br /&gt;    id = ID&lt;br /&gt;    maxOccurs = 1 : 1&lt;br /&gt;    minOccurs = (0 | 1) : 1&lt;br /&gt;    {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;    Content: (annotation?, (element | &lt;b&gt;any&lt;/b&gt;)*)&lt;br /&gt;  &amp;lt;/all&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Whereas, XSD 1.0 defined xs:all instruction as following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;all&lt;br /&gt;    id = ID&lt;br /&gt;    maxOccurs = 1 : 1&lt;br /&gt;    minOccurs = (0 | 1) : 1&lt;br /&gt;    {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;    Content: (annotation?, element*)&lt;br /&gt;  &amp;lt;/all&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 allows xs:any wild-card to be part of xs:all (whereas, XSD 1.0 didn't allow this), which makes xs:all instruction to be more useful (because, with xs:any we could make the Schema type more open). We could also have certain Schema constraints present as assertions (as illustrated in the example below), restricting the degree of Schema openness (achieved by xs:any wild-card) to an extent we would want.&lt;br /&gt;&lt;br /&gt;Here's an example I came up with, illustrating the use of xs:any wild-card within xs:all compositor, and having some assertions, for imposing some constraints on the ordering of elements (which means, that we are restricting the degree of openness achieved by xs:any using assertions) in the instance document:&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Person&amp;gt;&lt;br /&gt;    &amp;lt;fname&amp;gt;Mukul&amp;lt;/fname&amp;gt;&lt;br /&gt;    &amp;lt;lname&amp;gt;Gandhi&amp;lt;/lname&amp;gt;&lt;br /&gt;    &amp;lt;sex&amp;gt;M&amp;lt;/sex&amp;gt;&lt;br /&gt;    &amp;lt;address&amp;gt;&lt;br /&gt;      &amp;lt;street1&amp;gt;xyz&amp;lt;/street1&amp;gt;&lt;br /&gt;      &amp;lt;street2&amp;gt;street&amp;lt;/street2&amp;gt;&lt;br /&gt;      &amp;lt;street2&amp;gt;gurgaon&amp;lt;/street2&amp;gt;&lt;br /&gt;    &amp;lt;/address&amp;gt;&lt;br /&gt;  &amp;lt;/Person&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="Person"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:all&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="fname" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="lname" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="sex" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:any processContents="lax" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:all&amp;gt;&lt;br /&gt;        &amp;lt;xs:assert test="(*[1]/local-name() = ('fname', 'lname')) and &lt;br /&gt;                         (*[2]/local-name() = ('fname', 'lname'))" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the above Schema [2], if the assertions are not present, then xs:all compositor would mean, that it's contents can be present in any order (including the xs:any wild-card, which is newly introduced in XSD 1.1 within xs:all).&lt;br /&gt;&lt;br /&gt;The assertion in the Schema above [2], constrains the first two child elements of, "Person" element to be "fname" or "lname".&lt;br /&gt;&lt;br /&gt;&lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;'s XSD 1.1 processor, seems to implement these syntax fine.&lt;br /&gt;&lt;br /&gt;I hope that this post is useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1747995359108743979?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1747995359108743979/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1747995359108743979' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1747995359108743979'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1747995359108743979'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/xsd-11-wild-cards-in-compositor-and.html' title='XSD 1.1: wild-cards in xs:all compositor, and assertions'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5409634804365656569</id><published>2010-01-20T22:16:00.003+05:30</published><updated>2010-01-21T21:17:40.447+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xquery'/><title type='text'>XQuery 1.0: Full axis feature</title><content type='html'>I was just reading through the XQuery 1.0 language (I'm reading, &lt;a href="http://www.amazon.com/XQuery-Priscilla-Walmsley/dp/0596006349"&gt;Priscilla Walmsley's excellent book on XQuery&lt;/a&gt;), and found an interesting point specified in XQuery 1.0.&lt;br /&gt;&lt;br /&gt;The XQuery 1.0 spec says (&lt;a href="http://www.w3.org/TR/xquery/#id-full-axis-feature"&gt;Ref&lt;/a&gt;):&lt;br /&gt;&amp;lt;quote&amp;gt;&lt;br /&gt;[Definition: The following axes are designated as optional axes: ancestor, ancestor-or-self, following, following-sibling, preceding, and preceding-sibling.]&lt;br /&gt;&lt;br /&gt;[Definition: A conforming XQuery implementation that supports the Full Axis Feature MUST support all the optional axes.]&lt;br /&gt;&amp;lt;/quote&amp;gt;&lt;br /&gt;&lt;br /&gt;Giving a little thought about this, I felt that making certain XPath axes (and many of the useful ones, as specified above) as optional in XQuery language is most likely not correct, and would certainly trouble users, who want to uses these XPath axes out-of-the-box from an XQuery engine.&lt;br /&gt;&lt;br /&gt;Interestingly, the latest working draft of the &lt;a href="http://www.w3.org/TR/xquery-11/"&gt;XQuery language (the, 1.1 version)&lt;/a&gt; has fixed this design mistake (I think, this was a design mistake!), and doesn't specify such a constraint in XQuery language.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5409634804365656569?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5409634804365656569/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5409634804365656569' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5409634804365656569'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5409634804365656569'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/xquery-10-full-axis-feature.html' title='XQuery 1.0: Full axis feature'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4099286593094523540</id><published>2010-01-17T10:32:00.005+05:30</published><updated>2011-08-07T19:20:20.175+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='dtd'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Trang: DTD to XSD conversion</title><content type='html'>This morning, I was playing with &lt;a href="http://blog.jclark.com/"&gt;James Clark&lt;/a&gt;'s utility which can do conversion between different XML Schema languages.&lt;br /&gt;&lt;br /&gt;The utility is, Trang and it's described at:&lt;br /&gt;&lt;a href="http://www.thaiopensource.com/relaxng/trang.html"&gt;http://www.thaiopensource.com/relaxng/trang.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Here's a little example I tried with Trang (a DTD to XSD conversion).&lt;br /&gt;&lt;br /&gt;DTD input:&lt;br /&gt;&lt;pre&gt;  &amp;lt;!ELEMENT note (to,from,heading,body)&amp;gt;&lt;br /&gt;  &amp;lt;!ELEMENT to (#PCDATA)&amp;gt;&lt;br /&gt;  &amp;lt;!ELEMENT from (#PCDATA)&amp;gt;&lt;br /&gt;  &amp;lt;!ELEMENT heading (#PCDATA)&amp;gt;&lt;br /&gt;  &amp;lt;!ELEMENT body (#PCDATA)&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here's the XSD output I got from, Trang:&lt;br /&gt;&lt;pre&gt;  &amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"&amp;gt;&lt;br /&gt;    &amp;lt;xs:element name="note"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element ref="to"/&amp;gt;&lt;br /&gt;          &amp;lt;xs:element ref="from"/&amp;gt;&lt;br /&gt;          &amp;lt;xs:element ref="heading"/&amp;gt;&lt;br /&gt;          &amp;lt;xs:element ref="body"/&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;    &amp;lt;xs:element name="to" type="xs:string"/&amp;gt;&lt;br /&gt;    &amp;lt;xs:element name="from" type="xs:string"/&amp;gt;&lt;br /&gt;    &amp;lt;xs:element name="heading" type="xs:string"/&amp;gt;&lt;br /&gt;    &amp;lt;xs:element name="body" type="xs:string"/&amp;gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As per Trang documentation, following combination of conversions are possible:&lt;br /&gt;RELAX NG (both XML and compact syntax) &amp; DTD&lt;br /&gt;to&lt;br /&gt;RELAX NG (both XML and compact syntax), DTD &amp; XSD&lt;br /&gt;&lt;br /&gt;I found this good, and can recommend this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4099286593094523540?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4099286593094523540/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4099286593094523540' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4099286593094523540'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4099286593094523540'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/trang-dtd-to-xsd-conversion.html' title='Trang: DTD to XSD conversion'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2715676642063440373</id><published>2010-01-16T17:24:00.003+05:30</published><updated>2010-03-07T09:45:11.888+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: Open contents, with Xerces-J</title><content type='html'>Here's some further update to &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 feature implementation in &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Another significant feature, that's been added in XSD language (in, 1.1 version) is Open contents. It's defined on XSD complex types, and also at the schema level. A nice explanation about XSD 1.1 Open contents, is available in an article at, &lt;a href="http://www.ibm.com/developerworks/xml/library/x-xml11pt3/index.html#N1034D"&gt;http://www.ibm.com/developerworks/xml/library/x-xml11pt3/index.html#N1034D&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The wild-card instruction xs:any in XSD 1.0 was a way to implement XSD Open contents. XSD 1.1 introduces two new instructions, for implementing open contents namely, &amp;lt;xs:openContent&amp;gt; and &amp;lt;xs:defaultOpenContent&amp;gt;. These new XSD instructions have more options for the XSD schema authors, to write open schemas.&lt;br /&gt;&lt;br /&gt;I've been able to test couple of Open content examples, with current Xerces-J SVN code base, and Xerces-J implements them, sufficiently fine.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2715676642063440373?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2715676642063440373/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2715676642063440373' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2715676642063440373'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2715676642063440373'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/xsd-11-open-contents-with-xerces-j.html' title='XSD 1.1: Open contents, with Xerces-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8211795036886520502</id><published>2010-01-16T12:57:00.001+05:30</published><updated>2010-03-07T09:45:11.889+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XPath 2.0: PsychoPath processor update</title><content type='html'>I just noticed release of the &lt;a href="http://www.eclipse.org/webtools/development/news/3.2M4/"&gt;Eclipse, WTP (Web Tools Platform) 3.2M4 milestone&lt;/a&gt; (released on, December 11th, 2009). The &lt;a href="http://www.eclipse.org/webtools/development/news/3.2M4/sourceediting.php"&gt;WTP Source Editing release, in WTP 3.2M4 milestone&lt;/a&gt;, includes an enhanced &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;PsychoPath XPath 2.0 engine&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; users using the &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 support (specifically XSD 1.1 assertions and CTA/type alternatives), can use the latest PsychoPath library from &lt;a href="http://www.eclipse.org/webtools/"&gt;http://www.eclipse.org/webtools/&lt;/a&gt;. The latest development PsychoPath library can also be downloaded, from &lt;a href="https://build.eclipse.org/hudson/view/WTP/job/cbi-wtp-wst.xsl.psychopath/"&gt;https://build.eclipse.org/hudson/view/WTP/job/cbi-wtp-wst.xsl.psychopath/&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://intellectualcramps.blogspot.com/"&gt;Dave Carver&lt;/a&gt;, has been doing a great job in putting this all together.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8211795036886520502?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8211795036886520502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8211795036886520502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8211795036886520502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8211795036886520502'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/xpath-20-psychopath-processor-update.html' title='XPath 2.0: PsychoPath processor update'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7156353804354288137</id><published>2010-01-09T17:28:00.018+05:30</published><updated>2010-05-01T11:04:47.218+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: more XSD 1.1 tests; negative wild-cards</title><content type='html'>I'm pretty satisfied with the XSD 1.1 assertions and CTA (type alternatives) implementation (as I've been writing few posts about them, earlier on this blog), in current &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; SVN code base (though, a user feedback would be great, for the Xerces project. Instructions to report bugs in Xerces-J can be found at, &lt;a href="http://xerces.apache.org/xerces2-j/jira.html"&gt;http://xerces.apache.org/xerces2-j/jira.html&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;I'm now beginning to test some of other XSD 1.1 features. To start with these new set of posts, following are few use cases for "Negative wildcards" (ref, &lt;a href="http://www.ibm.com/developerworks/xml/library/x-xml11pt3/index.html#N101C9"&gt;http://www.ibm.com/developerworks/xml/library/x-xml11pt3/index.html#N101C9&lt;/a&gt;), which I've found to be working fine with Xerces-J.&lt;br /&gt;&lt;br /&gt;XSD 1.0 had following XML representation of, xs:any wild-card Schema component:&lt;br /&gt;&lt;pre&gt;  &amp;lt;any&lt;br /&gt;    id = ID&lt;br /&gt;    maxOccurs = (nonNegativeInteger | unbounded)  : 1&lt;br /&gt;    minOccurs = nonNegativeInteger : 1&lt;br /&gt;    namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) )  : ##any&lt;br /&gt;    processContents = (lax | skip | strict) : strict&lt;br /&gt;    {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;      Content: (annotation?)&lt;br /&gt;  &amp;lt;/any&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;("anyAttribute" is another wild-card Schema component)&lt;br /&gt;&lt;br /&gt;XSD 1.1 enhances the xs:any wild-card definition to following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;any&lt;br /&gt;    id = ID&lt;br /&gt;    maxOccurs = (nonNegativeInteger | unbounded)  : 1&lt;br /&gt;    minOccurs = nonNegativeInteger : 1&lt;br /&gt;    namespace = ((##any | ##other) | List of (anyURI | (##targetNamespace | ##local)) ) &lt;br /&gt;    notNamespace = List of (anyURI | (##targetNamespace | ##local)) &lt;br /&gt;    notQName = List of (QName | (##defined | ##definedSibling)) &lt;br /&gt;    processContents = (lax | skip | strict) : strict&lt;br /&gt;    {any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;      Content: (annotation?)&lt;br /&gt;  &amp;lt;/any&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As we could notice, xs:any now allows (in XSD 1.1, which was not available in XSD 1.0) two additional specifiers in it's definition, namely &lt;b&gt;"notNamespace"&lt;/b&gt; and &lt;b&gt;"notQName"&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;Here's a fictitious example of usage of "notNamespace" specifier:&lt;br /&gt;&lt;br /&gt;XML document, [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example xmlns="http://www.example.com/mySample"&amp;gt;&lt;br /&gt;    &amp;lt;a&amp;gt;hi there&amp;lt;/a&amp;gt;&lt;br /&gt;    &amp;lt;b&amp;gt;hi there ..&amp;lt;/b&amp;gt;&lt;br /&gt;    &amp;lt;c&amp;gt;hi there ...&amp;lt;/c&amp;gt;&lt;br /&gt;    &amp;lt;d xmlns="http://www.notallowed.com/sorry"&amp;gt;hi there ....&amp;lt;/d&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema, [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;             targetNamespace="http://www.example.com/mySample"&lt;br /&gt;             elementFormDefault="qualified"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="Example"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="a" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="b" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="c" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:any notNamespace="http://www.notallowed.com/sorry"&lt;br /&gt;                  processContents="lax"/&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The XSD schema, [2] defines an xs:any wild-card definition, which doesn't allow an XML instance document to have an element instance (allowed by the wild-card) to be in the namespace, "http://www.notallowed.com/sorry".&lt;br /&gt;&lt;br /&gt;Therefore when the XML instance, [1] is validated by XSD document, [2] we get following error while performing validation with Xerces-J XSD 1.1 schema engine:&lt;br /&gt;&lt;i&gt;test.xml:5:46:cvc-complex-type.2.4.a: Invalid content was found starting with element 'd'. One of '{WC[##other:"http://www.notallowed.com/sorry"]}' is expected.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;If we change the instance document, to specify element "d" to following:&lt;br /&gt;&amp;lt;d&amp;gt;hi there ....&amp;lt;/d&amp;gt;&lt;br /&gt;or say,&lt;br /&gt;&amp;lt;d xmlns="http://www.allowed.com"&amp;gt;hi there ....&amp;lt;/d&amp;gt;&lt;br /&gt;&lt;br /&gt;the XSD validation, succeeds (as element "d" is now not in the namespace, "http://www.notallowed.com/sorry").&lt;br /&gt;&lt;br /&gt;Here's an example for usage of "notQName" specifier:&lt;br /&gt;&lt;br /&gt;XML document, [3]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example xmlns="http://www.example.com/mySample"&amp;gt;&lt;br /&gt;    &amp;lt;a&amp;gt;hi there&amp;lt;/a&amp;gt;&lt;br /&gt;    &amp;lt;b&amp;gt;hi there ..&amp;lt;/b&amp;gt;&lt;br /&gt;    &amp;lt;c&amp;gt;hi there ...&amp;lt;/c&amp;gt;&lt;br /&gt;    &amp;lt;XX&amp;gt;hi there ....&amp;lt;/XX&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema, [4]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;             xmlns:tns="http://www.example.com/mySample"&lt;br /&gt;             targetNamespace="http://www.example.com/mySample"&lt;br /&gt;             elementFormDefault="qualified"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="Example"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="a" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="b" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="c" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:any notQName="tns:XX"&lt;br /&gt;                  processContents="lax"/&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The XSD schema, [4] doesn't allow an instance document to have, an element "XX" (in namespace, "http://www.example.com/mySample"), where the xs:any wild-card allows an element content.&lt;br /&gt;&lt;br /&gt;Therefore, when XML document [3] is validated by XSD schema, [4] we get following error message, with Xerces-J:&lt;br /&gt;&lt;i&gt;test.xml:5:7:cvc-complex-type.2.4.a: Invalid content was found starting with element 'XX'. One of '{WC[##any, notQName(tns:XX)]}' is expected.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;So if we, replace the offending element, with:&lt;br /&gt;&amp;lt;abc&amp;gt;hi there ....&amp;lt;/abc&amp;gt;&lt;br /&gt;or say,&lt;br /&gt;&amp;lt;XX xmlns="http://www.allowed.com"&amp;gt;hi there ....&amp;lt;/XX&amp;gt;&lt;br /&gt;(here, the local-name in XML instance document, is same as that specified in the "notQName" specifier, while the namespace of element instance is different, than specified by "notQName", which makes this element instance, valid)&lt;br /&gt;&lt;br /&gt;the XML validation passes.&lt;br /&gt;&lt;br /&gt;All these XSD language enhancements, in 1.1 version look cool (and, useful :)) to me, and they give some more XML validation capabilities to XSD schema, authors.&lt;br /&gt;&lt;br /&gt;Out of my curiosity, I was thinking &lt;b&gt;if we could write few of new XSD 1.1 wild-card capabilities, with assertions&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;For e.g, some of the features of "notNamespace" attribute can be written with an assertion like following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:assert test="not(namespace-uri(*[last()]) = (&lt;br /&gt;                        'http://www.notallowed.com/sorry1',&lt;br /&gt;                        'http://www.notallowed.com/sorry2',&lt;br /&gt;                        'http://www.notallowed.com/sorry3')&lt;br /&gt;                       )" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But using assertions for this need, might have following disadvantages, or limitations [5]:&lt;br /&gt;1. The XSD 1.1 engine, has to build a XPath tree to evaluate an assertion, which is a memory overhead.&lt;br /&gt;2. It looks like, that by using assertions, we cannot implement following facilities of "notNamespace" attribute: we cannot specify namespace URIs with keywords, ##targetNamespace &amp; ##local.&lt;br /&gt;3. Using the, "notNamespace" attribute on xs:any wildcard, gives us optimization benefits of xs:any implementation (like, this doesn't have to build a XPath tree, which an assertion approach requires). Moreover, it's better to use a native facility of a construct (like, xs:any), which keeps the XSD schema's design more natural, and easy to understand.&lt;br /&gt;&lt;br /&gt;And also, some of the features of "notQName" attribute can be written with an assertion like following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:assert test="not(local-name(*[last()]) eq 'XX'&lt;br /&gt;                       and&lt;br /&gt;                      namespace-uri(*[last()]) eq 'http://www.example.com/mySample')" /&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This approach would have similar issues, as specified above [5]. &lt;br /&gt;&lt;br /&gt;I hope, that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7156353804354288137?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7156353804354288137/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7156353804354288137' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7156353804354288137'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7156353804354288137'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/xerces-j-more-xsd-11-tests-negative.html' title='Xerces-J: more XSD 1.1 tests; negative wild-cards'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7334410849547436341</id><published>2010-01-01T13:02:00.005+05:30</published><updated>2010-03-07T09:45:11.890+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: few more assertions use cases; assertion inheritance</title><content type='html'>I'm continuing through, with writing uses cases for &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 assertions, and testing them with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;. Here's the next ones in this series:&lt;br /&gt;&lt;br /&gt;The uses cases below, demonstrate &lt;b&gt;XSD assertions usage in a XSD schema type hierarchy&lt;/b&gt;.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 1&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example x_count="3"&amp;gt;&lt;br /&gt;    &amp;lt;x a="val1"&amp;gt;2&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;x a="val2"&amp;gt;4&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;x a="val3"&amp;gt;6&amp;lt;/x&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 document [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;xs:element name="Example"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="x" type="x_Type" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;        &amp;lt;xs:attribute name="x_count" type="xs:nonNegativeInteger" use="required" /&amp;gt;&lt;br /&gt;        &amp;lt;xs:assert test="@x_count eq count(./x)" /&amp;gt;&lt;br /&gt;        &amp;lt;xs:assert test="every $x in x[position() lt last()] satisfies&lt;br /&gt;                    number($x/@a/substring-after(.,'val')) lt&lt;br /&gt;      number($x/following-sibling::x[1]/@a/substring-after(.,'val'))" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:complexType name="x_Type"&amp;gt;&lt;br /&gt;      &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;        &amp;lt;xs:extension base="myInteger"&amp;gt;&lt;br /&gt;          &amp;lt;xs:attribute name="a" type="attrType" use="required" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:simpleType name="myInteger"&amp;gt;&lt;br /&gt;      &amp;lt;xs:restriction base="xs:positiveInteger"&amp;gt;&lt;br /&gt;        &amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;    &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:simpleType name="attrType"&amp;gt;&lt;br /&gt;      &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;         &amp;lt;xs:pattern value="val[1-9][0-9]*" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:maxLength value="20" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;    &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The purpose of the XML document [1], and the corresponding XSD schema [2] would be quite self-explanatory I believe.&lt;br /&gt;&lt;br /&gt;I'll try to explain below, what the assertions in above XSD schema [2], are intended to accomplish:&lt;br /&gt;a) The assertion on complex type (an anonymous type) of element, "Example" is an usual assertion on a XSD complex type, as I've explained in few earlier posts in this series. For the interest of readers, this assertion is ensuring that, value of attribute "a" of element(s) "x" have a suffix integer value, to string "val" is specified in a numerically ascending order.&lt;br /&gt;b) The schema type, of element "x" is "x_Type". x_Type is a complex type (because, it specifies an attribute), and has simple content. The simple content definition of, element "x" is defined by the simple type, "myInteger". The type, myInteger specifies an assertion facet (which tests, that the integer value content, of element "x" is even). &lt;i&gt;This demonstrates, that a schema type (x_Type here) inherits assertions from it's base types (the assertions, all the way up in type hierarchy are inherited -- if any of the assertions, in some of ancestor XSD types are specified)&lt;/i&gt;.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 2&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;XML document [3]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example&amp;gt;&lt;br /&gt;    &amp;lt;x a="val1"&amp;gt;2&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;x a="val2"&amp;gt;4&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;x a="val3"&amp;gt;6&amp;lt;/x&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 document [4]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;xs:element name="Example"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="x" type="x_Type" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;        &amp;lt;xs:assert test="every $x in x[position() lt last()] satisfies&lt;br /&gt;                       number($x/@a/substring-after(.,'val')) lt&lt;br /&gt;         number($x/following-sibling::x[1]/@a/substring-after(.,'val'))" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:complexType name="x_Type"&amp;gt;&lt;br /&gt;      &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;        &amp;lt;xs:restriction base="x_base"&amp;gt;&lt;br /&gt;          &amp;lt;xs:assert test="$value lt 100" /&amp;gt; &lt;br /&gt;        &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:complexType name="x_base"&amp;gt;&lt;br /&gt;      &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;        &amp;lt;xs:extension base="myInteger"&amp;gt;&lt;br /&gt;          &amp;lt;xs:attribute name="a" type="attrType" use="required" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;      &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:simpleType name="myInteger"&amp;gt;&lt;br /&gt;      &amp;lt;xs:restriction base="xs:positiveInteger"&amp;gt;&lt;br /&gt;        &amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;    &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;  &lt;br /&gt;    &amp;lt;xs:simpleType name="attrType"&amp;gt;&lt;br /&gt;      &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;        &amp;lt;xs:pattern value="val[1-9][0-9]*" /&amp;gt;&lt;br /&gt;        &amp;lt;xs:maxLength value="20" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;    &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here's how the assertions in XSD schema [4], work on XML document, [3]:&lt;br /&gt;There's nothing too complicated about the assertion rules here. The assertions on the complex type, "x_Type" consists of assertions within this type, and the assertions inherited from the base type.&lt;br /&gt;&lt;br /&gt;The XSD examples, [2] and [4] look quite similar. The difference between XSD examples, [2] and [4] is that, the type "x_Type" in example [2] inherits a XSD simple type, while the type "x_Type" in example, [4] inherits a XSD complex type. The element, "Example" in XML document, [3] doesn't have an attribute, "x_count" (this is a cosmetic difference, between the two examples).&lt;br /&gt;&lt;br /&gt;Both of the above, XSD examples demonstrate assertions inheritance from base XSD types (one of the examples demonstrates inheriting assertions from a simple type, while the other example demonstrates inheriting assertions, from a complex type).&lt;br /&gt;&lt;br /&gt;I hope, that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7334410849547436341?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7334410849547436341/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7334410849547436341' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7334410849547436341'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7334410849547436341'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/xsd-11-few-more-assertions-use-cases.html' title='XSD 1.1: few more assertions use cases; assertion inheritance'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5084024958645588799</id><published>2010-01-01T10:49:00.000+05:30</published><updated>2010-01-01T10:49:56.604+05:30</updated><title type='text'>Happy New Year, 2010</title><content type='html'>As the new year dawns, here's a new year wish, to readers of this blog:&lt;br /&gt;&lt;br /&gt;&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/_MapgiCX5Lh0/Sz2Fid7vv3I/AAAAAAAAAAk/Pf-LlZlupf8/s1600-h/new-year.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/_MapgiCX5Lh0/Sz2Fid7vv3I/AAAAAAAAAAk/Pf-LlZlupf8/s640/new-year.jpg" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5084024958645588799?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5084024958645588799/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5084024958645588799' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5084024958645588799'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5084024958645588799'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2010/01/happy-new-year-2010.html' title='Happy New Year, 2010'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_MapgiCX5Lh0/Sz2Fid7vv3I/AAAAAAAAAAk/Pf-LlZlupf8/s72-c/new-year.jpg' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1207066863656264737</id><published>2009-12-13T17:06:00.012+05:30</published><updated>2010-03-07T09:45:11.891+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: few more assertions and CTA use cases</title><content type='html'>In my quest to test &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;'s &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 implementation, I've come up with another example, using XSD 1.1 assertions and CTA (type alternatives) which I'll like to share here.&lt;br /&gt;&lt;br /&gt;Here's a fictitious use-case and some discussions and analysis of the XSD technical options, for solving this use-case, later on in this post.&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;shapes&amp;gt;&lt;br /&gt;    &amp;lt;polygon kind="square"&amp;gt;&lt;br /&gt;      &amp;lt;a&amp;gt;10&amp;lt;/a&amp;gt;  &lt;br /&gt;      &amp;lt;b&amp;gt;10&amp;lt;/b&amp;gt;&lt;br /&gt;      &amp;lt;c&amp;gt;10&amp;lt;/c&amp;gt;&lt;br /&gt;      &amp;lt;d&amp;gt;10&amp;lt;/d&amp;gt;&lt;br /&gt;    &amp;lt;/polygon&amp;gt;&lt;br /&gt;    &amp;lt;polygon kind="rectangle"&amp;gt;&lt;br /&gt;      &amp;lt;a&amp;gt;10&amp;lt;/a&amp;gt;  &lt;br /&gt;      &amp;lt;b&amp;gt;8&amp;lt;/b&amp;gt;&lt;br /&gt;      &amp;lt;c&amp;gt;10&amp;lt;/c&amp;gt;&lt;br /&gt;      &amp;lt;d&amp;gt;8&amp;lt;/d&amp;gt;&lt;br /&gt;    &amp;lt;/polygon&amp;gt;&lt;br /&gt;    &amp;lt;polygon kind="triangle"&amp;gt;&lt;br /&gt;      &amp;lt;a&amp;gt;5&amp;lt;/a&amp;gt;  &lt;br /&gt;      &amp;lt;b&amp;gt;10&amp;lt;/b&amp;gt;&lt;br /&gt;      &amp;lt;c&amp;gt;15&amp;lt;/c&amp;gt;&lt;br /&gt;    &amp;lt;/polygon&amp;gt;&lt;br /&gt;  &amp;lt;/shapes&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XML document [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;shapes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&amp;gt;&lt;br /&gt;    &amp;lt;polygon kind="square" xsi:type="Quadrilateral"&amp;gt;&lt;br /&gt;      &amp;lt;a&amp;gt;10&amp;lt;/a&amp;gt;  &lt;br /&gt;      &amp;lt;b&amp;gt;10&amp;lt;/b&amp;gt;&lt;br /&gt;      &amp;lt;c&amp;gt;10&amp;lt;/c&amp;gt;&lt;br /&gt;      &amp;lt;d&amp;gt;10&amp;lt;/d&amp;gt;&lt;br /&gt;    &amp;lt;/polygon&amp;gt;&lt;br /&gt;    &amp;lt;polygon kind="rectangle" xsi:type="Quadrilateral"&amp;gt;&lt;br /&gt;      &amp;lt;a&amp;gt;10&amp;lt;/a&amp;gt;  &lt;br /&gt;      &amp;lt;b&amp;gt;8&amp;lt;/b&amp;gt;&lt;br /&gt;      &amp;lt;c&amp;gt;10&amp;lt;/c&amp;gt;&lt;br /&gt;      &amp;lt;d&amp;gt;8&amp;lt;/d&amp;gt;&lt;br /&gt;    &amp;lt;/polygon&amp;gt;&lt;br /&gt;    &amp;lt;polygon kind="triangle"&amp;gt;&lt;br /&gt;      &amp;lt;a&amp;gt;5&amp;lt;/a&amp;gt;  &lt;br /&gt;      &amp;lt;b&amp;gt;10&amp;lt;/b&amp;gt;&lt;br /&gt;      &amp;lt;c&amp;gt;15&amp;lt;/c&amp;gt;&lt;br /&gt;    &amp;lt;/polygon&amp;gt;&lt;br /&gt;  &amp;lt;/shapes&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [3]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="shapes"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="polygon" type="Triangular" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;             &amp;lt;xs:alternative test="@kind = ('square', 'rectangle')" type="Quadrilateral" /&amp;gt;&lt;br /&gt;           &amp;lt;/xs:element&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;   &lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;    &lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:complexType name="Triangular"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="a" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="b" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="c" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:attribute name="kind" type="xs:string" use="required" /&amp;gt;    &lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:complexType name="Quadrilateral"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;         &amp;lt;xs:extension base="Triangular"&amp;gt;&lt;br /&gt;           &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element name="d" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;           &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:assert test="if (@kind = 'square') then (a = b and b = c and c = d) else true()" /&amp;gt;&lt;br /&gt;           &amp;lt;xs:assert test="if (@kind = 'rectangle') then (a = c and b = d) else true()" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [4]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="shapes"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="polygon" type="Polygon" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;   &lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;    &lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:complexType name="Polygon"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="a" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="b" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="c" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="d" type="xs:positiveInteger" minOccurs="0" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:attribute name="kind" type="xs:string" use="required" /&amp;gt;&lt;br /&gt;       &amp;lt;xs:assert test="if (@kind = 'triangle') then not(d) else true()" /&amp;gt;&lt;br /&gt;       &amp;lt;xs:assert test="if (@kind = 'square') then (a = b and b = c and c = d) else true()" /&amp;gt;&lt;br /&gt;       &amp;lt;xs:assert test="if (@kind = 'rectangle') then (a = c and b = d) else true()" /&amp;gt;    &lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [5]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="shapes"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="polygon" type="Polygon" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;   &lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:complexType name="Polygon"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="a" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="b" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="c" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="d" type="xs:positiveInteger" minOccurs="0" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:attribute name="kind" use="required"&amp;gt;&lt;br /&gt;          &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;            &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;              &amp;lt;xs:enumeration value="square" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:enumeration value="rectangle" /&amp;gt;&lt;br /&gt;              &amp;lt;xs:enumeration value="triangle" /&amp;gt;&lt;br /&gt;            &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;          &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;       &amp;lt;/xs:attribute&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [6]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="shapes"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="polygon" type="Polygon" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;   &lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;    &lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:complexType name="Polygon"&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="a" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="b" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="c" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:attribute name="kind" use="required"&amp;gt;&lt;br /&gt;         &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;           &amp;lt;xs:restriction base="xs:string"&amp;gt;&lt;br /&gt;             &amp;lt;xs:enumeration value="square" /&amp;gt;&lt;br /&gt;             &amp;lt;xs:enumeration value="rectangle" /&amp;gt;&lt;br /&gt;             &amp;lt;xs:enumeration value="triangle" /&amp;gt;&lt;br /&gt;           &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;         &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;        &amp;lt;/xs:attribute&amp;gt;    &lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt; &lt;br /&gt;    &amp;lt;xs:complexType name="Quadrilateral"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;         &amp;lt;xs:extension base="Polygon"&amp;gt;&lt;br /&gt;           &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element name="d" type="xs:positiveInteger" /&amp;gt;&lt;br /&gt;           &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The goal of this use-case is following:&lt;br /&gt;To define a XSD content model, for the XML document [1].&lt;br /&gt;&lt;br /&gt;Solution of the use-case, and analysis:&lt;br /&gt;The XSD 1.1 way of solving this would be schema's, [3] or [4] (These are possible solutions, that come to my mind. There could be other solutions too).&lt;br /&gt;&lt;br /&gt;The Schema [3] uses both CTA and assertions. Whereas, Schema [4] uses only assertions. To solve this particular use-case, I might likely prefer Schema [4], because the content model defined in this schema is simpler/smaller, which is achieved by defining less of Schema types (only the 'Polygon' type here), and achieving further validation objectives, by defining assertions within this type.&lt;br /&gt;&lt;br /&gt;Though, Schema [3] is also an useful solution to this problem, which according to me depicts better XSD type modularity, and also offers better possibilies to reuse the types, defined here in other contexts/use-cases.&lt;br /&gt;&lt;br /&gt;But my gut feeling, is to go for Schema [4], for this use-case :)&lt;br /&gt;&lt;br /&gt;I am next trying to think, how to solve this use-case in XSD 1.0 way. Here are the things, that come to my mind (with some of of my analysis):&lt;br /&gt;1. Write a XSD Schema, as number [5] above. This is close to the desired solution of the use-case, described in this post. But this schema, doesn't solve this problem completely, as it doesn't strictly enforce the properties of a traingle (has 3 sides), square (has 4 sides, and all sides are equal) or a rectangle (has 4 sides, and opposite sides are equal). This is where, XSD assertions are really needed, if we want to specify XML validation entirely in the XSD layer (I think specifying much of XML validation in XSD layer is good, from application design point of view, as constraints specified with assertions, are entirely declarative and can be easily specified/modified by people, responsible for maintaining business rules, and without requiring to write say procedural code for these kind of validations, in imperative/OO languages like Java).&lt;br /&gt;2. Modify the XML instance, to something like [2]. i.e, make use of XSD 1.0 construct xsi:type (which needs to be specified in the XML instance document) in some way, and validate it with a Schema like, [6]. This solution again, doesn't (and I think with XSD 1.0, we cannot do so) enforce properties of different kind of polygons (as specified in point 1, above), and this also makes the XML document XSD language specific (because it contains the instruction, xsi:type from XSD namespace), making it inconvenient to use such an XML document in environments, where XSD is not available, or where XSD processing is not needed.&lt;br /&gt;&lt;br /&gt;The solutions presented in this post, are some of the possible ways, in which the given problem description here might be solved. But I can imagine, that there could be few other possibilities too (from XSD, syntax point of view), to solve such a use-case.&lt;br /&gt;&lt;br /&gt;That's all about, I wanted to write at the moment :)&lt;br /&gt;&lt;br /&gt;I hope that this post was useful!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1207066863656264737?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1207066863656264737/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1207066863656264737' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1207066863656264737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1207066863656264737'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/12/xsd-11-more-assertions-and-cta-use.html' title='XSD 1.1: few more assertions and CTA use cases'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4766876719674392127</id><published>2009-12-10T22:25:00.013+05:30</published><updated>2010-03-07T09:45:11.891+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XSD 1.1 assertions implementation updates</title><content type='html'>There have been some improvements lately, to the &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 assertions support in &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Here are the summary of recent assertion implementation changes, in Xerces-J:&lt;br /&gt;&lt;br /&gt;1) &lt;b&gt;XPath 2 expressions, in assertion facets should not access the XPath 2 context, because XPath context is "undefined" during assert facet evaluation&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;This implies that, the right way to invoke assertion facets, is as follows:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;    &amp;lt;xs:restriction base="xs:int"&amp;gt;&lt;br /&gt;      &amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;    &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;  &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;(i.e, we need to use the XPath "dynamic context" variable, $value to access the XSD simple type value.)&lt;br /&gt;&lt;br /&gt;If an attempt is made to access the XPath context in above XPath expression, like say as follows (using the expression, "." here):&lt;br /&gt;&amp;lt;xs:assertion test=". mod 2 = 0" /&amp;gt;&lt;br /&gt;&lt;br /&gt;Xerces returns an error message like, following:&lt;br /&gt;&lt;i&gt;test.xml:4:21:cvc-assertion.4.3.15.3: Assertion evaluation ('. mod 2 = 0') for element 'x (attribute =&amp;gt; a)' with type '#anonymous' did not succeed (undefined context).&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Or an XPath expression, like following:&lt;br /&gt;./@a mod 2 = 0&lt;br /&gt;&lt;br /&gt;Would result in a similar error.&lt;br /&gt;&lt;br /&gt;A special error message, was constructed (designating, "undefined context" to the user) in Xerces, for this use case.&lt;br /&gt;&lt;br /&gt;2) &lt;b&gt;Ability to evaluate assertions, on XML attributes&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;If attributes in XML document use user-defined XSD simple types, then assertions would also apply to attributes, as they do for XML elements.&lt;br /&gt;&lt;br /&gt;Following is a little example for this, use case.&lt;br /&gt;&lt;br /&gt;XML document:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example&amp;gt;&lt;br /&gt;    &amp;lt;x a="210"&amp;gt;101&amp;lt;/x&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Corresponding XSD 1.1 schema:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;xs:element name="Example"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="x" type="X_Type" maxOccurs="unbounded" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt; &lt;br /&gt;    &amp;lt;xs:complexType name="X_Type"&amp;gt;&lt;br /&gt;       &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;          &amp;lt;xs:extension base="xs:int"&amp;gt;&lt;br /&gt;             &lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:attribute name="a"&amp;gt;&lt;br /&gt;                &amp;lt;xs:simpleType&amp;gt;&lt;br /&gt;                   &amp;lt;xs:restriction base="xs:int"&amp;gt;&lt;br /&gt;                     &lt;i&gt;&amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;/i&gt;&lt;br /&gt;                   &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;                &amp;lt;/xs:simpleType&amp;gt;&lt;br /&gt;             &amp;lt;/xs:attribute&amp;gt;&lt;/span&gt;&lt;br /&gt;          &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;       &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Please note, that how we specify a XSD user-defined simple type for attribute "a" above, and an assertion facet on the simple type (there could by 0-n assertion facets here, as we have been looking at earlier).&lt;br /&gt;&lt;br /&gt;The assertion facet XPath expression, &lt;i&gt;$value mod 2 = 0&lt;/i&gt; would operate on the context variable, $value (which is the attribute's value) and such an assert facet doesn't have access to the XPath context (a "context undefined" error would be flagged by Xerces, if an attempt is made to access the XPath context).&lt;br /&gt;&lt;br /&gt;I hope, that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4766876719674392127?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4766876719674392127/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4766876719674392127' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4766876719674392127'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4766876719674392127'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/12/xerces-j-xsd-11-assertions.html' title='Xerces-J: XSD 1.1 assertions implementation updates'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1559283089410457158</id><published>2009-12-05T18:36:00.008+05:30</published><updated>2010-03-07T09:45:11.892+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XPath 2.0: PsychoPath XPath processor update</title><content type='html'>I've just run all the &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;PsychoPath XPath 2 processor&lt;/a&gt; (an &lt;a href="http://www.eclipse.org/webtools/sse/"&gt;Eclipse Web Tools, Source Editing sub-project&lt;/a&gt;) W3C test-suite tests, and here are the results for them:&lt;br /&gt;&lt;br /&gt;Tests: 8143&lt;br /&gt;Errors: 0&lt;br /&gt;Failures: 0&lt;br /&gt;&lt;br /&gt;So it seems, PsychoPath XPath engine passes, 100% of the W3C &lt;a href="http://www.w3.org/TR/xpath20/"&gt;XPath 2.0&lt;/a&gt; test suite, and some of it's own tests.&lt;br /&gt;&lt;br /&gt;This should be a moment of cheer, and wow!&lt;br /&gt;&lt;br /&gt;It also looks, like that the upcoming &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; release, 2.10.0 (ref, &lt;a href="http://wiki.apache.org/xerces/November2009"&gt;http://wiki.apache.org/xerces/November2009&lt;/a&gt;) would be getting almost a compliant XPath 2.0, engine for XSD 1.1 assertions and CTA.&lt;br /&gt;&lt;br /&gt;Ref: An earlier post about PsychoPath status: &lt;a href="http://mukulgandhi.blogspot.com/2009/09/psychopath-xpath-20-processor-update.html"&gt;http://mukulgandhi.blogspot.com/2009/09/psychopath-xpath-20-processor-update.html&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1559283089410457158?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1559283089410457158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1559283089410457158' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1559283089410457158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1559283089410457158'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/12/xpath-20-psychopath-xpath-processor.html' title='XPath 2.0: PsychoPath XPath processor update'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8814336430447030878</id><published>2009-11-28T10:56:00.022+05:30</published><updated>2010-03-07T09:45:11.893+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XSD 1.1 assertions on simple types</title><content type='html'>I'm trying to put up a post here, with few examples for assertions on XSD &lt;i&gt;simple types&lt;/i&gt;, and also for &lt;i&gt;complex types with simple contents&lt;/i&gt;, and testing them with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; XSD 1.1 implementation. The previous couple of posts on this blog, described assertions on XSD complex types having complex content (i.e, elements having "element only" or mixed content, and/or attributes).&lt;br /&gt;&lt;br /&gt;1) Here's an example, taken from &lt;a href="http://www.xfront.com/"&gt;Roger L. Costello&lt;/a&gt;'s collections of XSD 1.1 examples, which he's &lt;a href="http://www.xfront.com/xml-schema-1-1/"&gt;published on his web site&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example&amp;gt;&lt;br /&gt;    &amp;lt;even-integer&amp;gt;100&amp;lt;/even-integer&amp;gt;        &lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 document [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;schema xmlns="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;          elementFormDefault="qualified"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;element name="Example"&amp;gt;&lt;br /&gt;       &amp;lt;complexType&amp;gt;&lt;br /&gt;          &amp;lt;sequence&amp;gt;&lt;br /&gt;             &amp;lt;element name="even-integer"&amp;gt;&lt;br /&gt;                &amp;lt;simpleType&amp;gt;&lt;br /&gt;                  &amp;lt;restriction base="integer"&amp;gt;&lt;br /&gt;                     &amp;lt;assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;                  &amp;lt;/restriction&amp;gt;&lt;br /&gt;                &amp;lt;/simpleType&amp;gt;&lt;br /&gt;             &amp;lt;/element&amp;gt;&lt;br /&gt;          &amp;lt;/sequence&amp;gt;&lt;br /&gt;       &amp;lt;/complexType&amp;gt;&lt;br /&gt;    &amp;lt;/element&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above XSD 1.1 schema [2] constrains the XSD integer values, to only even ones (this works fine with Xerces!). XSD 1.1 defines a new facet named, &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-2-20090430/#rf-assertions"&gt;assertion&lt;/a&gt; on XSD built in simple types, which the above example describes.&lt;br /&gt;&lt;br /&gt;Please note that, "assertion" facet (applicable both to XSD &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-2-20090430/#rf-defn"&gt;simple types&lt;/a&gt;, and &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#dcl.ctd.ctsc"&gt;complex types with simple contents&lt;/a&gt;) is conceptually different than "assert" constraint on complex types (some of the explanation, about this is also given below as well).&lt;br /&gt;&lt;br /&gt;The XSD 1.1 spec mentions, that the assertions XPath 2 "dynamic context" get's augmented with a variable, $value. The XSD type of variable, $value is that of the base simple type (in this example, the type of $value is xs:integer). The detailed rules, for using variable $value in XSD 1.1 schemas are &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#sec-cvc-assertion"&gt;described, here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;It looks to me, that the ability to have an assertion facet on simple types, significantly enhances the XSD author's capability to provide many new constraints on simple type values, which were not possible in XSD 1.0 (for e.g, an ability to constrain integer values to be even, was not possible in XSD 1.0).&lt;br /&gt;&lt;br /&gt;For the above example, we could specify assertions to something like below, as well:&lt;br /&gt;&amp;lt;assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;&amp;lt;assertion test="$value lt 500" /&amp;gt;&lt;br /&gt;(i.e, a set of two assertion facet instances)&lt;br /&gt;&lt;br /&gt;Or perhaps, specifying only one assertion facet instance as following, &amp;lt;assertion test="($value mod 2 = 0) and ($value lt 500)" /&amp;gt; if user wishes, which realizes the same objective.  &lt;br /&gt;&lt;br /&gt;This enforces that the simple type value should be even, and also should be less than 500. Also, there are no limits to the number of assertion facet instances that can be specified. To my opinion, an ability to specify unlimited number of assertion facets (and also the assert constraints on complex types), makes assertions a tremendously useful XSD validation constructs.&lt;br /&gt;&lt;br /&gt;Notes: Interestingly, the following facet definition achieves the same results as met by the 2nd assertion facet instance, that's described above:&lt;br /&gt;&amp;lt;maxExclusive value="500" /&amp;gt;&lt;br /&gt;(this was available in, XSD 1.0 as well)&lt;br /&gt;&lt;br /&gt;2) Complex types with simple contents, using assertions:&lt;br /&gt;XML document [3]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;root&amp;gt;&lt;br /&gt;    &amp;lt;x label="a"&amp;gt;2&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;x label="b"&amp;gt;4&amp;lt;/x&amp;gt;&lt;br /&gt;  &amp;lt;/root&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here, the element "x" should have an attribute "label" with type xs:string. But the content of element "x" is simple (of type, xs:int for this example).&lt;br /&gt;Additional we also want, that the simple content value of "x", should be an even number.&lt;br /&gt;&lt;br /&gt;The XSD document for these validation constraints, is as follows [4]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt; &lt;br /&gt;   &amp;lt;xs:element name="root"&amp;gt;&lt;br /&gt;     &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="x" maxOccurs="unbounded" type="X_Type" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xs:complexType name="X_Type"&amp;gt;&lt;br /&gt;     &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;        &amp;lt;xs:extension base="xs:int"&amp;gt;    &lt;br /&gt;          &amp;lt;xs:attribute name="label" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:assert test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;     &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;   &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The use of xs:assert instruction is stressed in this example.&lt;br /&gt;&lt;br /&gt;It's interesting to see, that if we change value of one of "x" elements as follows:&lt;br /&gt;&amp;lt;x label="a"&amp;gt;21&amp;lt;/x&amp;gt;&lt;br /&gt;(I changed the first "x")&lt;br /&gt;&lt;br /&gt;Xerces fails the validation of XML instance, and returns following error message to the user:&lt;br /&gt;&lt;i&gt;test.xml:2:22:cvc-assertion.3.13.4.1: Assertion evaluation ('$value mod 2 = 0') for element 'x' with type 'X_Type' did not succeed.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Here, the XML validation did not succeed, because the value 21 is not an even number.&lt;br /&gt;&lt;br /&gt;3) The last example of this post is following:&lt;br /&gt;This describes the scenario of Complex types with simple contents. But here, the simple content get's its value by "restriction of a complex type". The previous example described Complex types with simple contents, using derivation by extension.&lt;br /&gt;&lt;br /&gt;The XML file remains same [3], while the new XSD document is following [5]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt; &lt;br /&gt;   &amp;lt;xs:element name="root"&amp;gt;&lt;br /&gt;     &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="x" maxOccurs="unbounded" type="X_Type" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xs:complexType name="X_Type"&amp;gt;&lt;br /&gt;     &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;        &amp;lt;xs:restriction base="x_base"&amp;gt;      &lt;br /&gt;           &lt;b&gt;&amp;lt;xs:assertion test="$value mod 2 = 0" /&amp;gt;&lt;br /&gt;           &amp;lt;xs:assert test="@label = ('a','b')" /&amp;gt;&lt;/b&gt;&lt;br /&gt;        &amp;lt;/xs:restriction&amp;gt;&lt;br /&gt;     &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;   &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xs:complexType name="x_base"&amp;gt;&lt;br /&gt;     &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;        &amp;lt;xs:extension base="xs:int"&amp;gt;    &lt;br /&gt;          &amp;lt;xs:attribute name="label" type="xs:string" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;     &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;   &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt; &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Please notice, how assertions are specified on the complex type, "X_Type" (shown with bold emphasis). Here, we have two assertion instructions (xs:assertion and xs:assert). In this example, xs:assertion is a facet for the atomic value, of the complex type (the value of complex type is simple in this case!). While xs:assert is the assertions instruction on the complex type (which has access to the element tree).&lt;br /&gt;&lt;br /&gt;The &lt;b&gt;complexType -&gt; simpleContent -&gt; restriction&lt;/b&gt;, type definition can specify assertions with following grammar:&lt;br /&gt;&lt;b&gt;... assertion*, ..., assert*&lt;/b&gt; (i.e, 0-n xs:assertion components can be followed by 0-n xs:assert components (this ordering is significant, otherwise the XSD 1.1 processor will flag an error).&lt;br /&gt;There could be other constructs as well, before xs:assertion here (and some after it. But anything after xs:assertion*, needs to be before the trailing xs:assert's). This is described in the relevant XSD 1.1 grammar at, &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#dcl.ctd.ctsc"&gt;http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#dcl.ctd.ctsc&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Notes: The XML Schema WG decided to have two different names for assertion instructions (xs:assertion and xs:assert), for this particular scenario, so that the XSD Schema authors could decide, whether they are writing assertions as a facet for simple values, or assertions for complex types (which have access to the element tree). If this naming distinction was not made in XSD 1.1 assertions, then specification of asserts in XSD documents, in this case would have caused ambiguity (i.e, the XSD 1.1 processor could not tell, which assertion is a facet, and which is an assertion for the complex type).&lt;br /&gt;&lt;br /&gt;Acknowledgements:&lt;br /&gt;I must mention that XSD 1.1 examples shared by Roger L. Costello, helped us fix quite a bit of bugs in Xerces assertions implementation. Our sincere thanks are due, to Roger. &lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;1. Reader's could also find this article useful, &lt;a href="http://www.ibm.com/developerworks/library/x-xml11pt2/"&gt;http://www.ibm.com/developerworks/library/x-xml11pt2/&lt;/a&gt; about XSD 1.1 co-occurence constraints, which describes XSD 1.1 assertions facility in detail.&lt;br /&gt;&lt;br /&gt;I hope that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8814336430447030878?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8814336430447030878/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8814336430447030878' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8814336430447030878'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8814336430447030878'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xerces-j-xsd-11-assertions-on-simple.html' title='Xerces-J: XSD 1.1 assertions on simple types'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6471692095016003789</id><published>2009-11-27T04:21:00.007+05:30</published><updated>2010-03-07T09:45:11.893+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: another assertions example with Xerces-J !</title><content type='html'>Here's another &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 assertions example, which I came up with today :)&lt;br /&gt;&lt;br /&gt;An XML document is something like below:&lt;br /&gt;&lt;pre&gt;  &amp;lt;person_db&amp;gt;&lt;br /&gt;    &amp;lt;person id="1"&amp;gt;&lt;br /&gt;      &amp;lt;fname&amp;gt;john&amp;lt;/fname&amp;gt;&lt;br /&gt;      &amp;lt;lname&amp;gt;backus&amp;lt;/lname&amp;gt;&lt;br /&gt;      &amp;lt;dob&amp;gt;1995-12-10&amp;lt;/dob&amp;gt;&lt;br /&gt;    &amp;lt;/person&amp;gt;&lt;br /&gt;    &amp;lt;person id="2"&amp;gt;&lt;br /&gt;      &amp;lt;fname&amp;gt;rick&amp;lt;/fname&amp;gt;&lt;br /&gt;      &amp;lt;lname&amp;gt;palmer&amp;lt;/lname&amp;gt;&lt;br /&gt;      &amp;lt;dob&amp;gt;2001-11-09&amp;lt;/dob&amp;gt;&lt;br /&gt;    &amp;lt;/person&amp;gt;&lt;br /&gt;    &amp;lt;person id="3"&amp;gt;&lt;br /&gt;      &amp;lt;fname&amp;gt;neil&amp;lt;/fname&amp;gt;&lt;br /&gt;      &amp;lt;lname&amp;gt;cooks&amp;lt;/lname&amp;gt;&lt;br /&gt;      &amp;lt;dob&amp;gt;1998-11-10&amp;lt;/dob&amp;gt;&lt;br /&gt;    &amp;lt;/person&amp;gt;&lt;br /&gt;  &amp;lt;/person_db&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Other than constraining the XML document to a structure like above, the XSD schema should specify following additional validation constraints, as well:&lt;br /&gt;1) Each person's dob field should specify a date, which must be later than or equal to the date, 1900-01-01.&lt;br /&gt;2) Each "person" element, should be sorted numerically according to "id" attribute, in an ascending fashion.&lt;br /&gt;&lt;br /&gt;I wanted to achieve these validation objectives, completely with XSD 1.1 assertions. Here's the XSD 1.1 document, which I find that works fine, with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt; &lt;br /&gt;     &amp;lt;xs:element name="person_db"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;          &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;            &amp;lt;xs:element name="person" maxOccurs="unbounded" type="Person" /&amp;gt;&lt;br /&gt;          &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:assert test="every $p in person[position() lt last()] satisfies&lt;br /&gt;                            ($p/@id lt $p/following-sibling::person[1]/@id)" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;   &lt;br /&gt;     &amp;lt;xs:complexType name="Person"&amp;gt;&lt;br /&gt;        &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="fname" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="lname" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;xs:element name="dob" type="xs:date" /&amp;gt;&lt;br /&gt;        &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;        &amp;lt;xs:attribute name="id" type="xs:int" use="required" /&amp;gt;&lt;br /&gt;        &amp;lt;xs:assert test="dob ge xs:date('1900-01-01')" /&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &lt;br /&gt;   &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Notes: It also seems, that above XSD validation requirements could be met, with following changes as well:&lt;br /&gt;1. Remove assertion from the complex type, "Person".&lt;br /&gt;2. Have an additional assertion on the element, "person_db" which will now look something like following:&lt;br /&gt;&amp;lt;xs:assert test="every $p in person[position() lt last()] satisfies&lt;br /&gt;($p/@id lt $p/following-sibling::person[1]/@id)" /&amp;gt;&lt;br /&gt;&amp;lt;xs:assert test="every $p in person satisfies ($p/dob ge xs:date('1900-01-01'))" /&amp;gt;&lt;br /&gt;&lt;br /&gt;i.e, we'll now have two assertions on the element, "person_db" (which are actually specified on the element's schema type).&lt;br /&gt;&lt;br /&gt;Though, I seem to like the first solution as it seems elegant to me, and more logically in place.&lt;br /&gt;&lt;br /&gt;I am happy, that this particular example worked fine as I expected, with Xerces. &lt;br /&gt;&lt;br /&gt;I hope that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6471692095016003789?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6471692095016003789/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6471692095016003789' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6471692095016003789'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6471692095016003789'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xsd-11-another-assertions-example-with.html' title='XSD 1.1: another assertions example with Xerces-J !'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4753575267795227589</id><published>2009-11-20T21:51:00.020+05:30</published><updated>2010-03-07T09:45:11.894+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: some CTA samples with Xerces-J</title><content type='html'>I've been trying to write few XSD 1.1 &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#cTypeAlternative"&gt;Conditional Type Assignment (CTA)&lt;/a&gt; samples, and trying them to run with the current &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; schema development SVN code.&lt;br /&gt;&lt;br /&gt;To start with, here's the first example (a very simple one indeed) that I find, which runs fine with Xerces-J:&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;root&amp;gt;&lt;br /&gt;    &amp;lt;x&amp;gt;hello&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;x kind="int"&amp;gt;10&amp;lt;/x&amp;gt;&lt;br /&gt;  &amp;lt;/root&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 document [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;     &amp;lt;xs:element name="root"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="x" type="xs:anyType" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;             &amp;lt;xs:alternative test="@kind='int'" type="xInt_Type" /&amp;gt;&lt;br /&gt;             &amp;lt;xs:alternative type="xString_Type" /&amp;gt;&lt;br /&gt;           &amp;lt;/xs:element&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;     &amp;lt;xs:complexType name="xInt_Type"&amp;gt;&lt;br /&gt;       &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;         &amp;lt;xs:extension base="xs:int"&amp;gt;&lt;br /&gt;           &amp;lt;xs:attribute name="kind" type="xs:string" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;       &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;     &amp;lt;xs:complexType name="xString_Type"&amp;gt;&lt;br /&gt;       &amp;lt;xs:simpleContent&amp;gt;&lt;br /&gt;         &amp;lt;xs:extension base="xs:string"&amp;gt;&lt;br /&gt;           &amp;lt;xs:attribute name="kind" type="xs:string" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;       &amp;lt;/xs:simpleContent&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Please note the presence of XSD 1.1 instruction, &lt;b&gt;xs:alternative&lt;/b&gt; (which is newly introduced in XSD 1.1, and makes this XSD Schema, a type alternative scenario), within the declaration for element, "x" in above schema [2]. If the value of "kind" attribute on element "x" is 'int', then a schema type "xInt_Type" will be assigned to element "x". If the attribute "kind" is not present on element, "x" or if it's present, and it's value if not 'int', the schema type xString_Type get's assigned to element, "x".&lt;br /&gt;&lt;br /&gt;Xerces-J successfully validates the above XML document [1] with the given XSD 1.1 Schema [2].&lt;br /&gt;&lt;br /&gt;If we introduce the following change to the XML document:&lt;br /&gt;&amp;lt;x kind="int"&amp;gt;not an int&amp;lt;/x&amp;gt;&lt;br /&gt;&lt;br /&gt;Xerces-J would display following error messages:&lt;br /&gt;&lt;i&gt;cvc-datatype-valid.1.2.1: 'not an int' is not a valid value for 'integer'.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;The above error message is correct, because the value 'not an int' in the XML document is not of type, xs:int.&lt;br /&gt;&lt;br /&gt;Notes:&lt;br /&gt;The schema types specified on xs:alternative instructions, need to validly derive (also referred to as, "type substitutable" in XSD 1.1 spec) from the default type specified on the element (which is, xs:anyType in this example), or the type on xs:alternative could be xs:error (this is a new schema type defined in XSD 1.1 spec, and is particularly useful with XSD type alternatives. The schema type xs:error has an empty lexical and value space, and any XML element or attribute which has this type, will always be invalid).&lt;br /&gt;&lt;br /&gt;So for example, if we write an element declaration like following (demonstrating type substitutability/derivation of XSD types, specified on xs:alternative instructions):&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:element name="x" type="xs:string" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;    &amp;lt;xs:alternative test="@kind='int'" type="xInt_Type" /&amp;gt;&lt;br /&gt;  ...&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Xerces-J would return following error message:&lt;br /&gt;e-props-correct.7: Type alternative 'xInt_Type' is not xs:error or is not validly derived from the type definition, 'string', of element 'x'.&lt;br /&gt;&lt;br /&gt;Making use of type xs:error, in CTAs:&lt;br /&gt;Let's assume, that XML document remains same as document [1], and declaration of element "x" is now written like following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:element name="x" type="xs:anyType" maxOccurs="unbounded"&amp;gt;&lt;br /&gt;    &amp;lt;xs:alternative test="@kind='int'" type="xInt_Type" /&amp;gt;&lt;br /&gt;    &amp;lt;xs:alternative type="xs:error" /&amp;gt;&lt;br /&gt;  &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now Xerces returns an error message like following:&lt;br /&gt;cvc-datatype-valid.1.2.1: 'hello' is not a valid value for 'error'.&lt;br /&gt;&lt;br /&gt;For this particular example, this error would occur if attribute "kind" is not present, or if the attribute "kind" is present, and it's value is not 'int'.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Xerces-J CTA implementation, using PsychoPath XPath 2 engine:&lt;/b&gt;&lt;br /&gt;The XSD 1.1 spec, defines a small &lt;a href="http://www.w3.org/TR/xmlschema11-1/#coss-ta"&gt;XPath 2 language subset&lt;/a&gt;, to be used by XSD 1.1 CTA instructions. Xerces-J has a native implementation of this XPath 2 subset (implemented by Hiranya Jayathilaka, a fellow Xerces-J committer), which get's selected by Xerces as a default XPath 2 processor, if CTA XPath 2 expressions conform to this XPath 2 subset (this was designed into Xerces, to make efficient XPath 2 evaluations using the CTA XPath 2 subset, since evaluating every XPath 2 expression with PsychoPath engine could have been computationally expensive).&lt;br /&gt;&lt;br /&gt;But if, the XSD CTA XPath 2 expressions cannot be compiled by the native Xerces-J CTA XPath 2 subset, Xerces will attempt to use the PsychoPath XPath engine to evaluate CTA XPath expressions, as a fall back option (and also to enable users to use the full XPath 2 language with Xerces CTA implementation, if they want to).&lt;br /&gt;&lt;br /&gt;To test, that PsychoPath engine does work with Xerces CTA implementation, I modified the type alternative instruction for the XSD example [2] above, to following:&lt;br /&gt;&amp;lt;xs:alternative test="@kind='int' and (tokenize('xxx xx', '\s+')[1] eq 'xxx')" type="xInt_Type" /&amp;gt;&lt;br /&gt;I added a dummy XPath "and" clause, which can only succeed with Xerces, if PsychoPath engine would evaluate this XPath expression. This additional "and" clause doesn't make any difference to the validity of the XML document [1], as in this example it would always evaluate to a boolean "true". If we try to introduce any error into the above XPath expression like say, to following:&lt;br /&gt;tokenize('xxx xx', '\s+')[1] eq 'xx' (please note the change from &lt;b&gt;eq 'xxx'&lt;/b&gt; to &lt;b&gt;eq 'xx'&lt;/b&gt;, which will cause this XPath expression to evaluate to a boolean "false"), Xerces would report a XML validity error, which is really expected of the Xerces CTA implementation.&lt;br /&gt;&lt;br /&gt;I hope that this post was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4753575267795227589?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4753575267795227589/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4753575267795227589' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4753575267795227589'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4753575267795227589'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xsd-11-conditional-type-assignment-cta.html' title='XSD 1.1: some CTA samples with Xerces-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-535661955650683238</id><published>2009-11-18T16:45:00.025+05:30</published><updated>2010-03-07T09:45:11.895+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XSD 1.1: some XSD 1.1 samples running with Xerces-J</title><content type='html'>I was thinking lately to functionally stress test, the upcoming &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; XSD 1.1 preview release (using the SVN code we have now, and later using the public binaries which will be provided by the Xerces project). I'm just curious to know, if there are any non-compliant parts in Xerces-J XSD 1.1 implementation, that I can find, which could probably serve as inputs to improving Xerces-J XSD 1.1 code base. To start with, I'll try to write few XSD 1.1 schemas, using the XSD 1.1 assertions and "Conditional Type Assignment (CTA)/type alternative" instructions.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Assertions examples&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 1&lt;/i&gt;&lt;br /&gt;Sample XML [1]&lt;br /&gt;&lt;pre&gt;  &amp;lt;x a="xyz"&amp;gt;&lt;br /&gt;    &amp;lt;foo&amp;gt;5&amp;lt;/foo&amp;gt;&lt;br /&gt;    &amp;lt;bar&amp;gt;10&amp;lt;/bar&amp;gt;&lt;br /&gt;  &amp;lt;/x&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [2]&lt;br /&gt;(Use Case: "the value of the foo element must be less than or equal to the value of the bar element")&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt; &lt;br /&gt;    &amp;lt;xs:element name="x"&amp;gt;&lt;br /&gt;      &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;         &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="foo" type="xs:int" /&amp;gt;&lt;br /&gt;           &amp;lt;xs:element name="bar" type="xs:int" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:attribute name="a" type="xs:string" use="required" /&amp;gt;&lt;br /&gt;         &amp;lt;xs:assert test="foo le bar" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;    &amp;lt;/xs:element&amp;gt;&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Using Xerces-J XSD 1.1 validator, the XML document [1] above validates fine with the given XSD document [2].&lt;br /&gt;&lt;br /&gt;If the assertion is written as follows (which is a false assertions. this is just to check for false assertions, and the error messages):&lt;br /&gt;&amp;lt;xs:assert test="(foo + 10) le bar" /&amp;gt;&lt;br /&gt;&lt;br /&gt;Then that would make the XML instance document ([1] above) invalid, and following error message is returned by Xerces:&lt;br /&gt;&lt;i&gt;test.xml:4:5:cvc-assertion.3.13.4.1: Assertion evaluation ('(foo + 10) le bar') for element 'x' with type '#anonymous' did not succeed.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;Use Case: "if the value of the attribute "a" is xyz, then the bar and baz elements are required, but otherwise they are optional".&lt;br /&gt;&lt;br /&gt;This would require following assertion definition:&lt;br /&gt;&amp;lt;xs:assert test="if (@a eq 'xyz') then (foo and bar) else true()" /&amp;gt;&lt;br /&gt;&lt;br /&gt;This works fine with Xerces-J.&lt;br /&gt;&lt;br /&gt;Acknowledgements: Thanks to Douglass A Glidden for contributing these use cases, on &lt;a href="http://www.xml.org/xml-dev/"&gt;xml-dev&lt;/a&gt; list.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 2&lt;/i&gt;&lt;br /&gt;Sample XML [3]&lt;br /&gt;&lt;pre&gt;  &amp;lt;Example&amp;gt;&lt;br /&gt;    &amp;lt;x&amp;gt;hi&amp;lt;/x&amp;gt;&lt;br /&gt;    &amp;lt;y&amp;gt;there&amp;lt;/y&amp;gt;&lt;br /&gt;    &amp;lt;ASomeNameSuffix/&amp;gt;&lt;br /&gt;  &amp;lt;/Example&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [4]&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;    &lt;br /&gt;    &amp;lt;xs:element name="Example" type="myType" /&amp;gt;&lt;br /&gt; &lt;br /&gt;    &amp;lt;xs:complexType name="myType"&amp;gt;&lt;br /&gt;      &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;        &amp;lt;xs:element name="x" type="xs:string" /&amp;gt;&lt;br /&gt;        &amp;lt;xs:element name="y" type="xs:string" /&amp;gt;&lt;br /&gt;        &amp;lt;xs:any processContents="lax" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;xs:assert test="starts-with(local-name(*[3]), 'A')" /&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In this particular example (Example 2), the immediate sibling element, of element "y" is defined via the XSD wild-card instruction, &amp;lt;xs:any/&amp;gt;. The assertion in XSD Schema [4] enforces, that name of the sibling element, that appears after element "y" must start with letter "A". I think, this could not have been accomplished (i.e, defining a constraint on an element name, in xs:any wild-card instruction) with XSD 1.0.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Example 3&lt;/i&gt;&lt;br /&gt;Sample XML [5]&lt;br /&gt;&lt;pre&gt;  &amp;lt;record&amp;gt;&lt;br /&gt;    &amp;lt;wins&amp;gt;20&amp;lt;/wins&amp;gt;&lt;br /&gt;    &amp;lt;losses&amp;gt;15&amp;lt;/losses&amp;gt;&lt;br /&gt;    &amp;lt;ties&amp;gt;8&amp;lt;/ties&amp;gt;&lt;br /&gt;    &amp;lt;!--&lt;br /&gt;      0 to n no's of well-formed elements, allowed here&lt;br /&gt;      by XSD wild-card instruction, &amp;lt;xs:any /&amp;gt;&lt;br /&gt;    --&amp;gt;&lt;br /&gt;  &amp;lt;/record&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 Schema [6]&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:complexType name="Record"&amp;gt;&lt;br /&gt;      &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;        &amp;lt;xs:element name="wins" type="xs:nonNegativeInteger"/&amp;gt;&lt;br /&gt;        &amp;lt;xs:element name="losses" type="xs:nonNegativeInteger"/&amp;gt;&lt;br /&gt;        &amp;lt;xs:element name="ties" type="xs:nonNegativeInteger" minOccurs="0"/&amp;gt;&lt;br /&gt;        &amp;lt;xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax"/&amp;gt;   &lt;br /&gt;      &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;xs:assert test="every $x in ties/following-sibling::* satisfies&lt;br /&gt;                     not(empty(index-of(('x','y','z'), local-name($x))))" /&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;xs:element name="record" type="Record"/&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The XSD schema, [6] validates the XML document [5]. The &amp;lt;xs:any ../&amp;gt; instruction in this schema ([6]) allows, 0-n number of well-formed XML elements after element, "ties". This facility was available in XSD 1.0 as well (for the interest of readers, XSD 1.1 has a weakened wild-card support, which makes the above XSD schema [6] valid -- in XSD 1.0 this schema was invalid, due to enforcement of UPA (unique particle attribution) constraint. An example of this is given in an article here, &lt;a href="http://www.ibm.com/developerworks/xml/library/x-xml11pt3/index.html#N10122"&gt;http://www.ibm.com/developerworks/xml/library/x-xml11pt3/index.html#N10122&lt;/a&gt;.).&lt;br /&gt;&lt;br /&gt;The assertion in this schema ([6]) enforces that, any element after element, "ties" which is allowed by the xs:any wild-card, should have a name (i.e, a name without namespace prefix -- a XML local-name) among this list, ('x', 'y', 'z'). Something like this, was not possible with XSD 1.0, and to my opinion this is nice :)&lt;br /&gt;&lt;br /&gt;PS: more examples to follow, in the next few posts :)&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;&lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/"&gt;XSD 1.1 Part 1: Structures&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-2-20090430/"&gt;XSD 1.1 Part 2: Datatypes&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I must acknowledge (a long enough acknowledgement. but I must do it anyway :)), that Xerces assertions is really powered by the &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;PsychoPath XPath 2 engine&lt;/a&gt;, and the credit for bringing PsychoPath engine to almost 100% compliance to W3C XPath 2.0 test suite (as of now, PsychoPath is 99% + compliant to the W3C XPath 2.0 test suite) should largely go to &lt;a href="http://intellectualcramps.blogspot.com/"&gt;Dave Carver&lt;/a&gt; and &lt;a href="http://www.selskabet.org/"&gt;Jesper Steen Møller&lt;/a&gt;. I was fortunate enough to contribute somewhat to PsychoPath XPath implementation (the freedom given to me as a &lt;a href="http://www.eclipse.org/webtools/sse/"&gt;Eclipse Source Editing&lt;/a&gt; project committer -- thanks to Dave Carver for this, helped me to drive Xerces assertions development quickly). Needless to mention the original PsychoPath code contribution by Andrea Bittau and his team, to &lt;a href="http://www.eclipse.org/webtools/"&gt;Eclipse Foundation&lt;/a&gt;. I must also mention the numerous  reviews, and improvements suggested by Khaled Noaman and general design advice by Michael Glavassevich (both are Xerces committers) helped tremendously while developing Xerces assertions. I must also mention Ken Cai's contribution, who wrote the original Xerces-PsychoPath interface, and also an initial implementation of that interface.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-535661955650683238?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/535661955650683238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=535661955650683238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/535661955650683238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/535661955650683238'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xsd-11-some-xsd-11-samples-running-with.html' title='XSD 1.1: some XSD 1.1 samples running with Xerces-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7229491744407749852</id><published>2009-11-14T20:04:00.015+05:30</published><updated>2010-03-07T09:45:11.896+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J XSD 1.1 update: bug fixes and enhancements</title><content type='html'>The &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; team did few enhancements to the &lt;a href="http://www.w3.org/XML/Schema"&gt;XSD&lt;/a&gt; 1.1 implementation, which solves few important XSD namespace URI issues, which affected Xerces assertions and Conditional Type Alternatives (CTA) implementation. These changes went into the Xerces-J SVN repository today.&lt;br /&gt;&lt;br /&gt;Here are the summary of these improvements:&lt;br /&gt;1) There is now an ability with Xerces-J XSD 1.1 implementation, to pass on the XSD language namespace prefix (which is declared on the XSD &amp;lt;schema&amp;gt; element), along with the XSD language URI as a prefix-URI binding pair to &lt;a href="http://wiki.eclipse.org/PsychoPathXPathProcessor"&gt;PsychoPath XPath 2.0 engine&lt;/a&gt;. This enhancement allows, the XSD language prefix declared on the "XSD 1.1 Schema instance" 's &amp;lt;schema&amp;gt; element to be used in the assertions and CTA XPath 2.0 expressions, for example as following:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" ...&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;    &amp;lt;xs:assert test="xs:string(test) eq 'xxx'" /&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;OR say,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" ...&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;    &amp;lt;xsd:assert test="xsd:string(test) eq 'xxx'" /&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;  &amp;lt;/xsd:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The earlier code in Xerces SVN (before the today's commit), hardcoded the XML Schema prefix to string, "xs" while communicating to the PsychoPath XPath 2 engine interface. That didn't allow the XPath 2 expressions in assertions and CTA to evaluate correctly (the Xerces code before this fix, always returned false for assertions, due to the presence of this bug), which used any other XSD prefix, like say "xsd" (even if the prefix "xsd" was bound to the XSD namespace, on the XSD root element, &amp;lt;schema&amp;gt;).&lt;br /&gt;&lt;br /&gt;This was a significant Xerces assertions and CTA bug, which got solved today, and the fix for this is now available on the &lt;a href="https://svn.apache.org/repos/asf/xerces/java/branches/xml-schema-1.1-dev/"&gt;Xerces-J XSD 1.1 development SVN repository&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;2) Another enhancement which went into Xerces-J SVN repository today, is the ability to specify the XPath 2.0 F&amp;O namespace declaration on the XSD document root element, &amp;lt;schema&amp;gt;.&lt;br /&gt;&lt;br /&gt;This enhancement makes possible something like, the following XSD 1.1 Schema to become valid:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="" xmlns:fn="http://www.w3.org/2005/xpath-functions" ...&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;     &amp;lt;xs:assert test="xs:string(test) eq fn:string('xxx')" /&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here the XML Schema author can, qualify the XPath 2 function calls in assertions XPath expressions, with the XPath 2 F&amp;O namespace prefix, like fn:string('xxx') above. The F&amp;O namespace prefix must be bound to the F&amp;O namespace URI, "http://www.w3.org/2005/xpath-functions" for such a XSD Schema to be valid. &lt;br /&gt;&lt;br /&gt;Even the following XSD 1.1 Schema is also valid (this happened to work correctly, earlier also before this Xerces SVN commit):&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="" ...&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;     &amp;lt;xs:assert test="xs:string(test) eq string('xxx')" /&amp;gt;&lt;br /&gt;    ...&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Here the XML Schema author, can use XPath 2 functions in Xerces assertions without specifying any prefix, for example like string('xxx') in the above example. The XPath 2 function calls without specifying the XPath 2 F&amp;O prefix, would work correctly for all the XPath 2.0 built in functions, in Xerces assertions XPath 2 expressions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7229491744407749852?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7229491744407749852/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7229491744407749852' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7229491744407749852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7229491744407749852'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xerces-j-xsd-11-update-bug-fixes-and.html' title='Xerces-J XSD 1.1 update: bug fixes and enhancements'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-968059133600682678</id><published>2009-11-14T10:31:00.003+05:30</published><updated>2010-09-05T21:16:12.755+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='grid'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><title type='text'>World community grid</title><content type='html'>There seems to be a nice initiative, &lt;a href="http://www.worldcommunitygrid.org/"&gt;"world community grid"&lt;/a&gt;. I think, IBM sponsors this community computing grid. I have been participating on this grid, since quite a few days now, and it really works! and I believe, it does make a difference to community good.&lt;br /&gt;&lt;br /&gt;This grid is composed by, computers which could be normal public personal computers at home, or office or any kind of computers that all can connect to the web. When a grid client is connected to the web, enabled by user authentication, the client computer participates in numerous public computing projects. Joining the grid, helps us to donate our computer's processing power to computations needed by these public projects, normally those that require massive computing simulations in short time.&lt;br /&gt;&lt;br /&gt;Joining the grid, doesn't disrupt the normal user activity on client computers, and the grid client intelligently utilizes memory (a very less amount of memory is needed by the grid client, while it works, which is normally as less as 5-10 MB) and the CPU, without disrupting anything for user's personal activities. It is also possible to configure the user's grid activity, about how to use one's CPU. Somebody may want to work in the default mode, or can give more CPU usage to the grid project tasks. The default mode works, well for me.&lt;br /&gt;&lt;br /&gt;All these details, and much more are available on the &lt;a href="http://www.worldcommunitygrid.org/"&gt;"world community grid"&lt;/a&gt;, web page.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-968059133600682678?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/968059133600682678/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=968059133600682678' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/968059133600682678'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/968059133600682678'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/world-community-grid.html' title='World community grid'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8954643880150834291</id><published>2009-11-13T21:58:00.000+05:30</published><updated>2010-03-07T09:45:11.896+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XML spec and XSD</title><content type='html'>A few days ago, I started of a pretty length discussion on &lt;a href="http://www.xml.org/xml-dev/"&gt;xml-dev mailing list&lt;/a&gt; about the following topic,&lt;br /&gt;&lt;br /&gt;"Should the &lt;a href="http://www.w3.org/TR/REC-xml/"&gt;W3C XML specification&lt;/a&gt; specify &lt;a href="http://www.w3.org/XML/Schema"&gt;XML Schema&lt;/a&gt; (a.k.a XSD) also as a XML validation language, as it specifies DTD (Document Type Definition)."&lt;br /&gt;&lt;br /&gt;The XML spec seems to convey, that an XML document is valid, *only* if it's valid according to a DTD. I had a contention to this point, and started of a debate on xml-dev list related to this question. I argued, that since there are now newer XML validation languages like XSD, &lt;a href="http://www.relaxng.org/"&gt;RelaxNG&lt;/a&gt;, &lt;a href="http://www.schematron.com/"&gt;Schematron&lt;/a&gt; etc, the XML spec now can modify the XML validation definition to refer to other XML Schema languages as well, rather than saying, that XML document is valid *only* if DTD is associated with the XML document.&lt;br /&gt;&lt;br /&gt;Unfortunately, may people who spoke on xml-dev, who have been working with XML for long, did not agree to this idea. But alas, I still feel I had/have a valid point about this :(&lt;br /&gt;&lt;br /&gt;I am referring to this threaded discussion again here, for records of this blog. Please follow this &lt;a href="http://markmail.org/thread/nv5kho6ovkifab25"&gt;link&lt;/a&gt;, if anybody wants to read this whole discussion.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8954643880150834291?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8954643880150834291/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8954643880150834291' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8954643880150834291'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8954643880150834291'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xml-spec-and-xsd.html' title='XML spec and XSD'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7450706876268146491</id><published>2009-11-01T10:22:00.024+05:30</published><updated>2009-11-02T19:24:02.848+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xalan'/><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>XSLT 1.0: Regular expression string tokenization, and Xalan-J</title><content type='html'>Some time ago, XSLT folks were debating on &lt;a href="http://www.mulberrytech.com/xsl/xsl-list/index.html"&gt;xsl-list&lt;/a&gt; (ref, &lt;a href="http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200910/msg00365.html"&gt;http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200910/msg00365.html&lt;/a&gt;) about how to implement string tokenizer functionality in XSLT. &lt;a href="http://www.w3.org/TR/xpath20/"&gt;XPath 2.0&lt;/a&gt; (and therefore, &lt;a href="http://www.w3.org/TR/xslt20/"&gt;XSLT 2.0&lt;/a&gt;) has a built in function for this need (ref, &lt;a href="http://www.w3.org/TR/xpath-functions/#func-tokenize"&gt;fn:tokenize&lt;/a&gt;). XPath 2.0 string tokenizer method, 'fn:tokenize' takes a string and a tokenizing regular expression pattern as arguments. This is something, which cannot be done natively in &lt;a href="http://www.w3.org/TR/xslt"&gt;XSLT 1.0&lt;/a&gt;. To do this, with XSLT 1.0 we need to write a recursive tokenizing "named XSLT template". But a "named XSLT template" using XSLT 1.0, for string tokenization has limitation, that it cannot accept natively an arbitrary regular expression, as a tokenizing delimiter.&lt;br /&gt;&lt;br /&gt;I got motivated enough, to write a &lt;b&gt;Java extension mechanism&lt;/b&gt; for regular expression based, string tokenization facility for XSLT 1.0 stylesheets, using the &lt;a href="http://xml.apache.org/xalan-j/"&gt;Xalan-J&lt;/a&gt; XSLT 1.0 engine.&lt;br /&gt;&lt;br /&gt;Here's Java code and a sample XSLT stylesheet for this particular, functionality:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;String tokenizer Xalan-J Java extension:&lt;/b&gt;&lt;br /&gt;&lt;pre&gt;package org.apache.xalan.xslt.ext;&lt;br /&gt;&lt;br /&gt;import javax.xml.parsers.DocumentBuilder;&lt;br /&gt;import javax.xml.parsers.DocumentBuilderFactory;&lt;br /&gt;import javax.xml.parsers.ParserConfigurationException;&lt;br /&gt;import org.apache.xpath.NodeSet;&lt;br /&gt;import org.w3c.dom.Document;&lt;br /&gt;&lt;br /&gt;public class XalanUtil {&lt;br /&gt;    public static NodeSet tokenize(String str, String regExp) throws ParserConfigurationException {&lt;br /&gt;      String[] tokens = str.split(regExp);&lt;br /&gt;      NodeSet nodeSet = new NodeSet();&lt;br /&gt;       &lt;br /&gt;      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;br /&gt;      DocumentBuilder docBuilder = dbf.newDocumentBuilder();&lt;br /&gt;      Document document = docBuilder.newDocument();&lt;br /&gt;       &lt;br /&gt;      for (int nodeCount = 0; nodeCount &lt; tokens.length; nodeCount++) {&lt;br /&gt;        nodeSet.addElement(document.createTextNode(tokens[nodeCount]));   &lt;br /&gt;      }&lt;br /&gt;       &lt;br /&gt;      return nodeSet;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;b&gt;Sample XSLT stylesheet, using the above Java extension (named, test.xsl):&lt;/b&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                version="1.0"                                                    &lt;br /&gt;                xmlns:java="http://xml.apache.org/xalan/java"&lt;br /&gt;                exclude-result-prefixes="java"&amp;gt;&lt;br /&gt;                 &lt;br /&gt;   &amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:param name="str" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:template match="/"&amp;gt;&lt;br /&gt;     &amp;lt;words&amp;gt;&lt;br /&gt;       &amp;lt;xsl:for-each select="java:org.apache.xalan.xslt.ext.XalanUtil.tokenize($str, '\s+')"&amp;gt;&lt;br /&gt;         &amp;lt;word&amp;gt;&lt;br /&gt;           &amp;lt;xsl:value-of select="." /&amp;gt;&lt;br /&gt;         &amp;lt;/word&amp;gt;&lt;br /&gt;       &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;     &amp;lt;/words&amp;gt;&lt;br /&gt;   &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;   &lt;br /&gt; &amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;&lt;/pre&gt;Now for e.g, when the above stylesheet is run with Xalan as follows:&lt;b&gt;java -classpath &amp;lt;path to the extension java class&amp;gt; org.apache.xalan.xslt.Process -in test.xsl -xsl test.xsl -PARAM str "hello world"&lt;/b&gt;, following output is produced:&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;words&amp;gt;&lt;br /&gt; &amp;lt;word&amp;gt;hello&amp;lt;/word&amp;gt;&lt;br /&gt; &amp;lt;word&amp;gt;world&amp;lt;/word&amp;gt;&lt;br /&gt;&amp;lt;/words&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This illustrates, that regular expression based string tokenization was applied as designed above, for XSLT 1.0 environment.&lt;br /&gt;&lt;br /&gt;The above Java extension, should be running fine with a min JRE level of, 1.4 as it relies on the JDK method, java.lang.String.split(String regex) which is available since JDK 1.4.&lt;br /&gt;&lt;br /&gt;PS: For easy reading and verboseness, the package name in the above Java extension class may be omitted, which will cause the corresponding XSLT instruction to be written like following:&lt;br /&gt;xsl:for-each select="java:XalanUtil.tokenize(... I would personally prefer this coding style, for production Java XSLT extensions. Though, this should not matter and to my opinion, decision to handle this can be left to individual XSLT developers.&lt;br /&gt;&lt;br /&gt;I hope, that this was useful.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7450706876268146491?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7450706876268146491/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7450706876268146491' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7450706876268146491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7450706876268146491'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/11/xslt-10-regular-expression-string.html' title='XSLT 1.0: Regular expression string tokenization, and Xalan-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3871553088578486299</id><published>2009-10-25T05:37:00.005+05:30</published><updated>2010-07-11T12:45:23.446+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='mozilla'/><title type='text'>Mozilla firefox and XPath namespace axis</title><content type='html'>&lt;a href="http://cmsmcq.com/"&gt;C. M. Sperberg-McQueen&lt;/a&gt; shared with us, that &lt;a href="http://www.mozilla.com/firefox/"&gt;Mozilla Firefox&lt;/a&gt; browser doesn't implement the XPath namespace axis (ref, &lt;a href="http://cmsmcq.com/mib/?p=757"&gt;http://cmsmcq.com/mib/?p=757&lt;/a&gt;). CMSMcQ has encouraged us to cast a vote on Mozilla forum, to push Firefox team, to implement XPath namespace axis. I agree with CMSMcQ, and also find that XPath namespace axis is quite a critical functionality for XPath data model. This is certainly true for &lt;a href="http://www.w3.org/TR/xpath/"&gt;XPath 1.0&lt;/a&gt;, where namespace axis is very critical (and Mozilla, implements XPath 1.0). In &lt;a href="http://www.w3.org/TR/xpath20/"&gt;XPath 2.0&lt;/a&gt;, namespace axis is deprecated but namespace nodes still is a core part of, XPath 2.0 data model as well.&lt;br /&gt;&lt;br /&gt;I have already casted my vote for this with my support at, &lt;a href="https://bugzilla.mozilla.org/show_bug.cgi?id=94270"&gt;https://bugzilla.mozilla.org/show_bug.cgi?id=94270&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Other's might follow, please.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3871553088578486299?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3871553088578486299/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3871553088578486299' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3871553088578486299'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3871553088578486299'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/10/mozilla-firefox-and-xpath-namespace.html' title='Mozilla firefox and XPath namespace axis'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-28720743908661911</id><published>2009-10-24T09:57:00.001+05:30</published><updated>2009-10-24T09:58:22.252+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='uml'/><category scheme='http://www.blogger.com/atom/ns#' term='oo'/><title type='text'>Martin Fowler: UML Distilled, 3rd Edition</title><content type='html'>I have been reading &lt;a href="http://martinfowler.com/"&gt;Martin Fowler&lt;/a&gt;'s book, "UML Distilled, 3rd Edition" since last few months (my book reading has been very slow, keeping in mind the time I spend on web these days, to do most of my learnings).&lt;br /&gt;&lt;br /&gt;This is a great UML book (and has only, 175 pages but very good), and I recommend it to anybody wanting to know about &lt;a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language"&gt;UML (Unified Modeling Language)&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-28720743908661911?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/28720743908661911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=28720743908661911' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/28720743908661911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/28720743908661911'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/10/martin-fowler-uml-distilled.html' title='Martin Fowler: UML Distilled, 3rd Edition'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3293178026663670469</id><published>2009-10-24T07:20:00.001+05:30</published><updated>2009-11-02T23:56:36.603+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>How XPath compare values in prediates</title><content type='html'>A user asked question similar to following, on IBM developerWorks XQuery and XPath forum:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;What does &lt;b&gt;A = B&lt;/b&gt; and &lt;b&gt;A != B&lt;/b&gt; mean in XPath expressions?&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;&lt;a href="http://saxonica.blogharbor.com/blog"&gt;Michael Kay&lt;/a&gt; provided a very nice explanation to this:&lt;br /&gt;The operators "=" and "!=" in XPath use "implicit existential quantification". So A=B is shorthand for "some $a in A, $b in B satisfies $a eq $b" (the longhand form is legal in XPath 2.0), while A!=B is shorthand for "some $a in A, $b in B satisfies $a ne $b".&lt;br /&gt;&lt;br /&gt;So, not(A=B) is true if there is no pair of items from A and B that are equal, while (A!=B) is true if there is a pair of values that are not equal. In practice, you nearly always want not(A=B).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3293178026663670469?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3293178026663670469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3293178026663670469' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3293178026663670469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3293178026663670469'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/10/how-xpath-compare-values-in-prediates.html' title='How XPath compare values in prediates'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3646150691988302732</id><published>2009-09-27T21:33:00.004+05:30</published><updated>2009-09-27T21:40:20.132+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='oo'/><title type='text'>OO multiple inheritance, and Java</title><content type='html'>I have been thinking again, about multiple inheritance and why Java doesn't support it. I &lt;a href="http://mukulgandhi.blogspot.com/2009/06/multiple-inheritance-in-java.html"&gt;wrote a bit&lt;/a&gt; about this topic, some time ago. &lt;br /&gt;&lt;br /&gt;There are so, so many resources on web about this, and it's actually very easy to find the answer to this, via a simple web search. Here is an article from where I started to know an answer to this,  &lt;a href="http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html"&gt;http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html&lt;/a&gt;, which pointed me to this &lt;a href="http://java.sun.com/docs/white/langenv/"&gt;white paper&lt;/a&gt; by &lt;a href="http://blogs.sun.com/jag/"&gt;James Gosling&lt;/a&gt; and Henry McGilton. Really, I did not read this white paper by Java creators earlier (it never came across my eyes :)), in spite being familiar and working with Java since long time. Sometimes, we find gems on web in an unexpected ways (I mean, this paper is a gem for me :)). I'll try to read this paper (hopefully fully, and being able to understand it) over the next few days.&lt;br /&gt;&lt;br /&gt;And &lt;a href="http://java.sun.com/docs/white/langenv/Simple.doc2.html#4090"&gt;here is a link in this white paper&lt;/a&gt;, which explains why Java doesn't support multiple inheritance. &lt;a href="http://java.sun.com/docs/white/langenv/Simple.doc2.html#4076"&gt;The following white paper link&lt;/a&gt; is also interesting, which gives a complete overview of C and C++ features, that were omitted in Java language (Java has been influenced from C and C++).&lt;br /&gt;&lt;br /&gt;My personal opinion is, that if we must need to use multiple inheritance, we should just try to write programs in C++. On the contrary, my experience in using Java for about a decade, convinces me, that Java is suitable to solve almost any business application problem, and absence of multiple inheritance in Java, is not an hindrance to design good programming abstractions for problem domain. The advantages like Java's byte code portability and web friendliness far outweigh, any disadvantages caused by absence of multiple inheritance. On numerous occasions, I have created Java byte code on Windows, and used it without modification on Unix based systems (and vice versa). This is something which is built into the Java language, and it is cool!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3646150691988302732?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3646150691988302732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3646150691988302732' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3646150691988302732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3646150691988302732'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/09/oo-multiple-inheritance-and-java.html' title='OO multiple inheritance, and Java'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8162540199086303154</id><published>2009-09-20T19:08:00.012+05:30</published><updated>2010-03-07T09:45:11.897+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XML Schema 1.1 Conditional Type Alternatives (CTA), enhancements</title><content type='html'>&lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Apache Xerces-J&lt;/a&gt; team has made enhancements, to the way &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#cTypeAlternative"&gt;XML Schema 1.1, Conditional Type Alternatives (CTA)&lt;/a&gt; are evaluated.&lt;br /&gt;&lt;br /&gt;Following are summary of the recent XML Schema 1.1 CTA enhancements, being done in Xerces-J:&lt;br /&gt;&lt;br /&gt;1) The XML Schema 1.1 spec, allows the implementations to use a &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#coss-ta"&gt;smaller XPath 2.0 subset for CTA&lt;/a&gt;, and can also provide the full XPath 2.0 language, for CTA evaluations.&lt;br /&gt;&lt;br /&gt;Xerces-J had the smaller XPath 2.0 susbset already implemented, for CTA since quite some time (which was contributed by Hiranya Jayathilaka), and that was the only XPath 2.0 support which, Xerces-J CTA implementation had earlier. Xerces-J team recently added full XPath 2.0 support as well, for XML Schema 1.1 CTA, using the PsychoPath XPath 2.0 engine (which is used, by Xerces-J assertions facility as well).&lt;br /&gt;&lt;br /&gt;If the user, writes XPath 2.0 expressions adhering to the XPath 2.0 subset for CTA, then the native XPath 2.0 implementation in Xerces-J shall process those XPath expressions. But if the XPath expression parsing fails by the native Xerces-J XPath 2.0 processor, Xerces-J falls back to the PsychoPath processor for XPath evaluation, allowing users to use the full XPath 2.0 language, for CTA.&lt;br /&gt;&lt;br /&gt;2) Some time ago, Xerces-J implemented the XSD 1.1 data type, &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#xsd-error"&gt;xs:error&lt;/a&gt; as well, which is useful in XML Schema 1.1 CTA.&lt;br /&gt;&lt;br /&gt;It's been quite a pleasure, working on some of these patches.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8162540199086303154?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8162540199086303154/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8162540199086303154' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8162540199086303154'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8162540199086303154'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/09/xerces-j-xml-schema-11-conditional-type.html' title='Xerces-J: XML Schema 1.1 Conditional Type Alternatives (CTA), enhancements'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3780660893498645509</id><published>2009-09-20T13:26:00.013+05:30</published><updated>2010-03-07T09:45:11.898+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XML Schema 1.1 assertions enhancements</title><content type='html'>The XML Schema 1.1 language, defines an assertions facility (&lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#cAssertions"&gt;xs:assert&lt;/a&gt; and &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-2-20090430/#rf-assertions"&gt;xs:assertion&lt;/a&gt;), which constrain the XML Schema simple and complex types.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Apache Xerces-J&lt;/a&gt; implements XML Schema 1.1 assertions. As described in the XSD 1.1 spec, assertions typically have following XML representation:&lt;br /&gt;&lt;pre&gt;  &amp;lt;assert&lt;br /&gt;    id = ID&lt;br /&gt;    test = an XPath expression&lt;br /&gt;    xpathDefaultNamespace = (anyURI | (##defaultNamespace | ##targetNamespace | ##local)) &lt;br /&gt;{any attributes with non-schema namespace . . .}&amp;gt;&lt;br /&gt;    Content: (annotation?)&lt;br /&gt; &amp;lt;/assert&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;For XML Schema simple type facets, the assertions are named, xs:assertion (as opposed to the xs:assert instruction for complex types) and rest of assertion contents are same.&lt;br /&gt;&lt;br /&gt;Some background about XML Schema 1.1 assertions, and it's implementation in Xerces-J, could be referred at following &lt;a href="http://mukulgandhi.blogspot.com/2009/04/xml-schema-11-assertions.html"&gt;blog post&lt;/a&gt;, which I wrote some time ago.&lt;br /&gt;&lt;br /&gt;During the last week, we enhanced Xerces-J assertions to support the assertions attribute, &lt;span style="font-weight:bold;"&gt;'xpathDefaultNamespace'&lt;/span&gt;. I did contribute this patch to Xerces-J, and it's now available on Xerces-J SVN repository.&lt;br /&gt;&lt;br /&gt;The following &lt;a href="http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#declare-assertion"&gt;XML Schema 1.1, specification description&lt;/a&gt;, describes how an assertions attribute 'xpathDefaultNamespace' works (please see the section, "XML Mapping Summary for XPath Expression Property Record {default namespace}").&lt;br /&gt;&lt;br /&gt;Here's a simple example, about how 'xpathDefaultNamespace' functions in XML Schema 1.1 assertions:&lt;br /&gt;&lt;br /&gt;XML document [1]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;X xmlns="http://xyz"&amp;gt;&lt;br /&gt;    &amp;lt;message&amp;gt;hello&amp;lt;/message&amp;gt;&lt;br /&gt;  &amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;XSD 1.1 document [2]:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;             targetNamespace="http://xyz"&lt;br /&gt;             elementFormDefault="qualified"&amp;gt;&lt;br /&gt;&lt;br /&gt;     &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;       &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;          &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;             &amp;lt;xs:element name="message" type="xs:string" /&amp;gt;&lt;br /&gt;          &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;          &amp;lt;xs:assert test="message = 'hello'" xpathDefaultNamespace="##targetNamespace" /&amp;gt;&lt;br /&gt;       &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;     &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/xs:schema&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the XML document [1] above, since element "message" belongs to the namespace, "http://xyz" (by virtue of the default namespace declaration, xmlns="http://xyz" on element "X"), therefore the XPath (2.0) expression &lt;span style="font-weight:bold;"&gt;message = 'hello'&lt;/span&gt;, on xs:assert instruction would return a boolean value "true", only if an element reference "message" in the XPath expression belongs to the namespace, "http://xyz". This namespace information needs to be provided to the XPath engine, via the 'xpathDefaultNamespace' attribute, on xs:assert instruction. If for the above XML instance document [1], 'xpathDefaultNamespace' attribute is not provided on the xs:assert instruction, then the XPath expression, &lt;span style="font-weight:bold;"&gt;message = 'hello'&lt;/span&gt; would return false (as then, the element "message" would be considered in no/null namespace, by the XPath engine), and the element instance at runtime, would become invalid according to such a XSD 1.1 Schema.&lt;br /&gt;&lt;br /&gt;Allowing the 'xpathDefaultNamespace' attribute to be working on XML Schema 1.1 assertions, further increases the usefulness of XML Schema 'assertions' instruction, because now the XPath expressions, on assertions can be XML namespace aware.&lt;br /&gt;&lt;br /&gt;The implementation of 'xpathDefaultNamespace' attribute on assertions, required enhancing &lt;a href="http://www.eclipse.org/webtools/"&gt;PsychoPath XPath 2.0 engine&lt;/a&gt; as well. The updated PsychoPath library, JAR has been copied to Xerces-J SVN repository as well.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3780660893498645509?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3780660893498645509/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3780660893498645509' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3780660893498645509'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3780660893498645509'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/09/xerces-j-xml-schema-11-assertions.html' title='Xerces-J: XML Schema 1.1 assertions enhancements'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-9167700178705224977</id><published>2009-09-12T20:16:00.008+05:30</published><updated>2010-03-07T09:45:11.899+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XML Schema 1.1 inheritable attributes and CTA</title><content type='html'>I just had my XML Schema 1.1 inheritable attributes patch, and it's integration with XML Schema 1.1 Conditional Type Assignment (CTA) facility, committed to &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; XML Schema 1.1 SVN dev stream. I had &lt;a href="http://mukulgandhi.blogspot.com/2009/08/xml-schema-11-inheritable-attributes.html"&gt;earlier written about this&lt;/a&gt;, on this blog.&lt;br /&gt;&lt;br /&gt;Credits for Xerces-J inheritable attributes work, should also go to Khaled Noaman (a fellow Xerces-J committer), who reviewed my patch and suggested many improvements. The Xerces-J inheritable attributes work, adds to an earlier work for XML Schema 1.1 Conditional Type Assignment (CTA), by Hiranya Jayathilaka (also a fellow Xerces-J committer).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-9167700178705224977?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/9167700178705224977/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=9167700178705224977' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/9167700178705224977'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/9167700178705224977'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/09/xerces-j-xml-schema-11-inheritable.html' title='Xerces-J: XML Schema 1.1 inheritable attributes and CTA'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7954780994802592793</id><published>2009-09-08T09:22:00.011+05:30</published><updated>2010-03-07T09:34:54.454+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>PsychoPath XPath 2.0 processor update</title><content type='html'>Some time ago, I wrote a &lt;a href="http://mukulgandhi.blogspot.com/2009/07/eclipse-psychopath-xpath-20-processor.html"&gt;progress update&lt;/a&gt;, about PsychoPath XPath 2.0 processor's (an &lt;a href="http://www.eclipse.org/webtools/sse/"&gt;Eclipse, Web Tools Source Editing&lt;/a&gt; subproject) compliance with, W3C XPath 2.0 test suite.&lt;br /&gt;&lt;br /&gt;As of today, following are the test suite success rate, for PsychoPath engine:&lt;br /&gt;&lt;br /&gt;Tests: 8137&lt;br /&gt;Failures: 163&lt;br /&gt;Errors: 5&lt;br /&gt;&lt;br /&gt;This reflects a success rate of: 97.9%.&lt;br /&gt;&lt;br /&gt;I think, these recent PsychoPath improvements with W3C XPath 2.0 test suite, reflect a much increased quality of PsychoPath product.&lt;br /&gt;&lt;br /&gt;I am hoping, we would reach 100% test suite compliance, with PsychoPath in a near future!&lt;br /&gt;&lt;br /&gt;Credits, for most of the recent PsychoPath improvements, should go to &lt;a href="http://intellectualcramps.blogspot.com/"&gt;Dave Carver&lt;/a&gt; and &lt;a href="http://www.selskabet.org/"&gt;Jesper Steen Møller&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Update on 2009-09-18:&lt;/span&gt; Took an update today from the Eclipse CVS servers, for PsychoPath source code, and following are the W3C XPath 2.0 test results:&lt;br /&gt;Tests: 8137&lt;br /&gt;Failures: 132&lt;br /&gt;Errors: 5&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Update on 2009-10-17:&lt;/span&gt; As of today, following are the W3C XPath 2.0 test results:&lt;br /&gt;Tests: 8137&lt;br /&gt;Failures: 81&lt;br /&gt;Errors: 1&lt;br /&gt;&lt;br /&gt;This reflects the W3C XPath 2.0 test suite pass percentage, for PsychoPath engine of about 98.9%. It seems, we are moving closer to the 100% test success rate, for PsychoPath. Dave Carver has been working a lot, on these improvements during last few days.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7954780994802592793?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7954780994802592793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7954780994802592793' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7954780994802592793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7954780994802592793'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/09/psychopath-xpath-20-processor-update.html' title='PsychoPath XPath 2.0 processor update'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7462111826559716264</id><published>2009-09-05T22:53:00.011+05:30</published><updated>2010-03-07T09:45:11.899+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Roger L. Costello: About XML Schema 1.1</title><content type='html'>&lt;a href="http://www.xfront.com/"&gt;Roger L. Costello&lt;/a&gt; a brilliant thinker, about XML and related technologies, has recently posted extensive study materials related to XML Schema 1.1, on his web site (ref, &lt;a href="http://www.xfront.com/xml-schema-1-1/"&gt;http://www.xfront.com/xml-schema-1-1/&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;Roger mentions, Saxon 9.2 as one of the products that implements XML Schema 1.1 features.&lt;br /&gt;&lt;br /&gt;From the information I have from &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Apache Xerces-J&lt;/a&gt; developer's forum, I am happy to share with the community, that Apache Xerces-J is planning to release, a preview of XML Schema 1.1 implementation, by around the end of this year (i.e, Dec, 2009). A latest snapshot of Xerces-J XML Schema 1.1 source code repository and related dependencies, is located at, &lt;a href="https://svn.apache.org/repos/asf/xerces/java/branches/xml-schema-1.1-dev/"&gt;https://svn.apache.org/repos/asf/xerces/java/branches/xml-schema-1.1-dev/&lt;/a&gt;. User's are welcome to build binaries from the sources, available here and try XML Schema 1.1 features, currently implemented in Apache Xerces-J. Much of the XML Schema 1.1 features, are implemented at this Xerces-J snapshot URL.&lt;br /&gt;&lt;br /&gt;References:&lt;br /&gt;1) &lt;a href="http://www.w3.org/TR/xmlschema11-1/"&gt;XML Schema Definition Language (XSD) 1.1 Part 1: Structures&lt;/a&gt;&lt;br /&gt;2) &lt;a href="http://www.w3.org/TR/xmlschema11-2/"&gt;XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7462111826559716264?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7462111826559716264/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7462111826559716264' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7462111826559716264'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7462111826559716264'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/09/roger-l-costello-xml-schema-11.html' title='Roger L. Costello: About XML Schema 1.1'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2637336718682233257</id><published>2009-08-22T22:14:00.011+05:30</published><updated>2010-05-01T05:32:28.973+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='dom'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XML document validation, while parsing with Java DOM API</title><content type='html'>I spent few hours, discovering this while working with the DOM XML parsing API, and using it with &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;, in a Java program.&lt;br /&gt;&lt;br /&gt;I wanted to parse an XML document in Java using a plain DOM parser, along with doing validation, using either W3C XML Schema or a DTD.&lt;br /&gt;&lt;br /&gt;Following is a sequence of instructions which needs to be written for this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();&lt;br /&gt;dbf.setNamespaceAware(true);&lt;br /&gt;dbf.setValidating(true);&lt;br /&gt;SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);&lt;br /&gt;Schema schema = schemaFactory.newSchema ...&lt;br /&gt;dbf.setSchema(schema);&lt;br /&gt;DocumentBuilder docBuilder = dbf.newDocumentBuilder();&lt;br /&gt;docBuilder.parse(..&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;These statements, are all that are necessary to accomplish this task. But there, are few catches here, which I wish to share.&lt;br /&gt;&lt;br /&gt;1) If dbf.setValidating(true) is specified, then a DTD is mandatory. Even if W3C XML Schema is provided with dbf.setSchema .., parsing would fail, since dbf.setValidating(true) was specified, and if a DTD is absent.&lt;br /&gt;&lt;br /&gt;2) If we only want to do validation with W3C XML Schema, then we shouldn't specify dbf.setValidating(true), which is required only for DTD validation.&lt;br /&gt;&lt;br /&gt;I spent a few hours discovering this, and thought that somebody might benefit from this post.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2637336718682233257?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2637336718682233257/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2637336718682233257' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2637336718682233257'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2637336718682233257'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/08/xml-document-validation-while-parsing.html' title='XML document validation, while parsing with Java DOM API'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7031963670491567351</id><published>2009-08-08T21:56:00.022+05:30</published><updated>2010-03-07T09:45:11.901+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XML Schema 1.1: inheritable attributes, and it's implementation in Apache Xerces-J</title><content type='html'>The XML Schema 1.1, language has defined a new facility to define &lt;a href="http://www.w3.org/TR/xmlschema11-1/#Inherited_attributes"&gt;attributes as inheritable&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;The XML Schema, attribute definition(s) can now specify an additional property (in 1.1 version of the XML Schema language), &lt;b&gt;inheritable&lt;/b&gt;&lt;b&gt; &lt;/b&gt;(having a schema type, xs:boolean), which will indicate that all the descendant elements to the element (which specifies an inheritable attribute), can access the inheritable attribute by it's name.&lt;br /&gt;&lt;br /&gt;It could first appear to the reader of the XML Schema 1.1 spec, that inheritable attributes are something, which can physically be present (i.e., a copy of it) on descendant elements. But this is not the correct interpretation of the inheritable attributes concept. I'll try to illustrate this point with few examples in this post.&lt;br /&gt;&lt;br /&gt;Please consider the following XML Schema 1.1, fragment:&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;    &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;      &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;        &amp;lt;xs:element name="Y" type="xs:string" /&amp;gt;&lt;br /&gt;      &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;xs:attribute name="attr" type="xs:int" &lt;b&gt;inheritable&lt;/b&gt;&lt;b&gt;="true"&lt;/b&gt; /&amp;gt;&lt;br /&gt;    &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;  &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This corresponds to, an XML structure like following:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;X attr="1"&amp;gt;&lt;br /&gt;    &amp;lt;Y&amp;gt;hello&amp;lt;/Y&amp;gt;&lt;br /&gt;  &amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The above XML Schema 1.1 fragment, indicates that attribute, "attr" is inheritable. The word inheritable seems to convey, that the following XML fragment could be valid as well, for the above XML Schema 1.1 fragment:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;X attr="1"&amp;gt;&lt;br /&gt;    &amp;lt;Y attr="1"&amp;gt;hello&amp;lt;/Y&amp;gt;&lt;br /&gt;  &amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;But this interpration of inheritable attributes is not correct&lt;/span&gt;. The inheritable attributes, cannot be physically copied to the descendant elements. In the above examples, the Schema type of element, "Y" is a simple type (i.e., xs:string). So how, could Y have an attribute, "attr" (since by definition, elements with simple types cannot have attributes)? Only XML Schema "complex types", can specify attributes. XML Schema 1.1, inheritable attributes do not change the nature of XML Schema simple types, and simple contents. The presence of attributes on any XML element, is governed only by the attribute declarations on the complex type definition of the element. This meaning for attributes with respect to XSD complex types is preserved, in XML Schema 1.1 as well.&lt;br /&gt;&lt;br /&gt;Then it's interesting to think, that what could be the use of specifying the attribute as inheritable (when it cannot be physically present in the descendant elements)?&lt;br /&gt;&lt;br /&gt;Inheritable attributes, are useful in a XML Schema 1.1 facility, like Conditional Type Assignment (CTA) / type alternatives.&lt;br /&gt;&lt;br /&gt;Please consider the following XML Schema 1.1 example, defining an XML element and it's Schema type, using CTA and inheritable attributes:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;xs:element name="X"&amp;gt;&lt;br /&gt;     &amp;lt;xs:complexType&amp;gt;&lt;br /&gt;       &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;         &amp;lt;xs:element name="Y" type="xs:anyType"&amp;gt;&lt;br /&gt;           &amp;lt;xs:alternative test="@attr = 'INT'" type="xs:int" /&amp;gt;&lt;br /&gt;           &amp;lt;xs:alternative type="xs:error" /&amp;gt;&lt;br /&gt;         &amp;lt;/xs:element&amp;gt;&lt;br /&gt;       &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;       &amp;lt;xs:attribute name="attr" type="xs:int" inheritable="true" /&amp;gt;&lt;br /&gt;     &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;   &amp;lt;/xs:element&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;As per the above Schema (using type alternatives), the following XML instance is valid:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;X attr="INT"&amp;gt;&lt;br /&gt;    &amp;lt;Y&amp;gt;100&amp;lt;/Y&amp;gt;&lt;br /&gt;  &amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;But the following XML instance would be invalid:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;  &amp;lt;X attr="INT"&amp;gt;&lt;br /&gt;    &amp;lt;Y&amp;gt;hello&amp;lt;/Y&amp;gt;&lt;br /&gt;  &amp;lt;/X&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The inheritable attribute is also particularly useful, to define the attribute &lt;span style="font-weight: bold;"&gt;xml:lang&lt;/span&gt; as inheritable in XML elements.&lt;br /&gt;&lt;br /&gt;I got to know these facts, after raising a query last week, to W3C XML Schema comments forum.&lt;br /&gt;&lt;br /&gt;I am thankful to following gentlemen, for answering my queries, on the W3C XML Schema forum:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://cmsmcq.com/mib"&gt;C. M. Sperberg-McQueen&lt;/a&gt;&lt;br /&gt;&lt;a href="http://domino.research.ibm.com/comm/research_people.nsf/pages/noah.index.html"&gt;Noah Mendelsohn&lt;/a&gt;&lt;br /&gt;&lt;a href="http://saxonica.blogharbor.com/blog"&gt;Michael Kay&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The fact, which I really wanted to share on this blog post (other than, sharing what the XML Schema, inheritable attributes are used for), was that I've written an implementation of inheritable attributes, for &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Apache Xerces-J&lt;/a&gt;'s XML Schema 1.1 validator. I've submitted a patch for this, to Apache Xerces-J JIRA issue tracking system.&lt;br /&gt;&lt;br /&gt;This patch currently, has a full implementation of attribute syntax changes (i.e, the presence of inheritable attribute itself, and it's binding with the XML Schema type, xs:boolean).&lt;br /&gt;&lt;br /&gt;I'm in a process to, enhance the Xerces-J implementation of Conditional Type Assignment (CTA) facility, to be able to use inheritable attributes. I hope to complete the CTA changes in Xerces-J, for inheritable attributes in near future.&lt;br /&gt;&lt;br /&gt;After all necessary reviews are done for this patch, by Xerces-J committers, I hope to have the inheritable attributes implementation, go to Xerces-J SVN repository, which will in most likelihood subsequently become part of an official future release, of Xerces-J.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style: italic;"&gt;2009-08-14:&lt;/span&gt; Today, I submitted all the Conditional Type Assignment (CTA) related changes, for inheritable attributes, to Apache Xerces-J JIRA issue tracking system. I would say, the XML Schema 1.1 inheritable attributes, and it's integration with CTA is completed, for Xerces-J. I'm feeling good about it :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7031963670491567351?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7031963670491567351/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7031963670491567351' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7031963670491567351'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7031963670491567351'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/08/xml-schema-11-inheritable-attributes.html' title='XML Schema 1.1: inheritable attributes, and it&apos;s implementation in Apache Xerces-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4765108394327541605</id><published>2009-07-30T14:06:00.003+05:30</published><updated>2009-07-31T16:29:13.347+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='linux'/><title type='text'>Grady Booch: about Linux, and TTY interfaces</title><content type='html'>Reading through &lt;a href="http://en.wikipedia.org/wiki/Grady_Booch"&gt;Grady Booch&lt;/a&gt;'s latest &lt;a href="https://www.ibm.com/developerworks/mydeveloperworks/blogs/gradybooch/entry/linux_institutional_memory"&gt;blog post&lt;/a&gt;, I found that Grady has shared interesting information about TTY interfaces in Linux, and of UNIX based systems.&lt;br /&gt;&lt;br /&gt;I read &lt;a href="http://www.linusakesson.net/programming/tty/index.php"&gt;the article&lt;/a&gt;, which Grady pointed, almost completely and found it a great read.&lt;br /&gt;&lt;br /&gt;Something interesting to share, I thought!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4765108394327541605?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4765108394327541605/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4765108394327541605' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4765108394327541605'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4765108394327541605'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/07/grady-booch-about-linux-and-tty.html' title='Grady Booch: about Linux, and TTY interfaces'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-987070365862169671</id><published>2009-07-18T20:39:00.003+05:30</published><updated>2009-07-18T20:49:16.931+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='theory'/><title type='text'>Niklaus Wirth: On current state of software development, and future</title><content type='html'>Navigating from &lt;a href="http://en.wikipedia.org/wiki/Niklaus_Wirth"&gt;Dr. Niklaus Wirth's wikipedia web page&lt;/a&gt;, I could find a very interesting interview conversation, Dr. Wirth had, on the following web site (ref, &lt;a href="http://www.eptacom.net/pubblicazioni/pub_eng/wirth.html"&gt;http://www.eptacom.net/pubblicazioni/pub_eng/wirth.html&lt;/a&gt;). &lt;br /&gt;&lt;br /&gt;This interview is dated, in 1997. I found Dr. Wirth's views in this interview, quite good to read.&lt;br /&gt;&lt;br /&gt;Something interesting to share, I thought!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-987070365862169671?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/987070365862169671/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=987070365862169671' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/987070365862169671'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/987070365862169671'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/07/niklaus-wirth-on-current-state-of.html' title='Niklaus Wirth: On current state of software development, and future'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5517752478358048813</id><published>2009-07-12T14:05:00.019+05:30</published><updated>2009-07-18T22:22:52.383+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='theory'/><title type='text'>Niklaus Wirth: On recursive algorithms</title><content type='html'>I have started reading the computer science, classic collection &lt;span style="font-weight:bold;"&gt;"ALGORITHMS + DATA STRUCTURES = PROGRAMS"&lt;/span&gt; by &lt;a href="http://en.wikipedia.org/wiki/Niklaus_Wirth"&gt;Niklaus Wirth&lt;/a&gt;. Dr. Wirth wrote this text in 1975. It's a great book.&lt;br /&gt;&lt;br /&gt;Though "recursive algorithms" are widely known to computer science community since long time, I still could find some good advice in Dr. Wirth's book on usage of recursive algorithms.&lt;br /&gt;&lt;br /&gt;Dr. Wirth mentions:&lt;br /&gt;"An object is said to be recursive if it partially consists or is defined in terms of itself. Recursion is a particularly powerful means in mathematical definitions. The power of recursion evidently lies in the possibility of defining an infinite set of objects by a finite statement. In the same manner, an infinite number of computations can be described by a finite recursive program, even if this program contains no explicit repetitions."&lt;br /&gt;&lt;br /&gt;We all know, what recursive algorithms are. It's a widely known programming technique. But I found particularly the advice, &lt;span style="font-weight:bold;"&gt;"When not to use recursion"&lt;/span&gt; in Dr. Wirth's book very worth while to apply.&lt;br /&gt;&lt;br /&gt;Dr. Wirth further mentions:&lt;br /&gt;"Recursive algorithms are particularly appropriate when the underlying problem or the data to be treated are defined in recursive terms. This does not mean, however, that such recursive definitions guarantee that a recursive algorithm is the best way to solve the problem.&lt;br /&gt;&lt;br /&gt;Programs in which the use of algorithmic recursion is to be &lt;span style="font-weight:bold;"&gt;avoided&lt;/span&gt; can be characterized by a schema which exhibits the pattern of their composition. Such schema's can described as following:&lt;br /&gt;&lt;br /&gt;[1]&lt;br /&gt;P =&gt; &lt;span style="font-weight:bold;"&gt;if&lt;/span&gt; B &lt;span style="font-weight:bold;"&gt;then&lt;/span&gt; (S; P)&lt;br /&gt;&lt;br /&gt;or, equivalently&lt;br /&gt;&lt;br /&gt;P =&gt; (S; &lt;span style="font-weight:bold;"&gt;if&lt;/span&gt; B &lt;span style="font-weight:bold;"&gt;then&lt;/span&gt; P)&lt;br /&gt;"&lt;br /&gt;&lt;br /&gt;Dr. Wirth illustrates this principle with a well known, recursive definition of the factorial computation (mentioned below):&lt;br /&gt;&lt;br /&gt;F0 = 1&lt;br /&gt;F(i+1) = (i + 1) * f(i)&lt;br /&gt;&lt;br /&gt;Dr. Wirth maps the factorial problem with the recursive anti-pattern he defines ([1] above):&lt;br /&gt;&lt;br /&gt;[2]&lt;br /&gt;P =&gt; if I &lt; n then (I := I + 1; F := I * F; P)&lt;br /&gt;I := 0; F := 1; P&lt;br /&gt;&lt;br /&gt;In the above definition [2], S (ref, [1]) refers to,&lt;br /&gt;I := I + 1; F := I * F&lt;br /&gt;&lt;br /&gt;Dr. Wirth in the book, illustrates a following, iterative definition of factorial computation:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;I := 0;&lt;br /&gt;F := 1;&lt;br /&gt;&lt;span style="font-weight:bold;"&gt;while&lt;/span&gt; I &lt; n &lt;span style="font-weight:bold;"&gt;do&lt;/span&gt;&lt;br /&gt;  &lt;span style="font-weight:bold;"&gt;begin&lt;/span&gt; I := I + 1; F := I * F&lt;br /&gt;  &lt;span style="font-weight:bold;"&gt;end&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Dr. Wirth says, "The lesson to draw is to avoid the use of recursion when there is an &lt;span style="font-style:italic;"&gt;obvious&lt;/span&gt; solution by iteration.&lt;br /&gt;This, however, should not lead to shying away from recursion at any price. The fact that implementations of recursive procedures on essentially non-recursive machines exists proves that for practical purposes every recursive program can be transformed into a purely iterative one. This, however, involves the explicit handling of a recursion stack, and these operations will often obscure the essence of a program to such an extent that it becomes most difficult to comprehend. The lesson is that algorithms which by their nature are recursive rather than iterative should be formulated as recursive procedures."&lt;br /&gt;&lt;br /&gt;Just thought of sharing a bit of text, from this nice book and encouraging readers to read the book!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5517752478358048813?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5517752478358048813/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5517752478358048813' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5517752478358048813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5517752478358048813'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/07/niklaus-wirth-on-recursive-algorithms.html' title='Niklaus Wirth: On recursive algorithms'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6665802822234276446</id><published>2009-07-04T12:16:00.013+05:30</published><updated>2009-08-09T09:51:39.838+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>PsychoPath XPath 2.0 processor update</title><content type='html'>&lt;a href="http://intellectualcramps.blogspot.com/"&gt;Dave Carver&lt;/a&gt; and I have been trying to improve the Eclipse XPath 2.0 processor (a.k.a PsychoPath) during last couple of weeks. My motivation to keep working on PsychoPath engine has been a desire, to help Eclipse and Apache (&lt;a href="http://mukulgandhi.blogspot.com/2009/05/xerces-j-assertions-implementation-and.html"&gt;Apache Xerces-J uses PsychoPath engine for XML Schema 1.1 processing&lt;/a&gt;) communities to be able to have a highly compliant XPath 2.0 engine.&lt;br /&gt;&lt;br /&gt;Dave has written today, &lt;a href="http://intellectualcramps.blogspot.com/2009/07/eclipse-psychopath-xpath-20-processor.html"&gt;a progress update of PsychoPath development&lt;/a&gt; on this blog. I feel, we now have a pretty good XPath 2.0 implementation with PsychoPath. We are continuing to work on remaining non-compliant items, with PsychoPath. The remaining non compliance cases, to my opinion are near edge cases which users don't use too often. But we'll continue to solve them, with each future day and weeks.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Update on 2009-07-11:&lt;/span&gt;  During last couple of days, Dave Carver has made quite a few useful improvements to PsychoPath, and the W3C XPath 2.0 test suite within Eclipse. I took an update today of the latest PsychoPath sources, and the XPath 2.0 test suite, and following are the latest test results:&lt;br /&gt;&lt;br /&gt;Total tests: 8137&lt;br /&gt;Failures: 811&lt;br /&gt;Errors: 48&lt;br /&gt;&lt;br /&gt;This reflects, the test pass success rate of about 89.5%. I think, this is quite good. Lot of credit of these improvements should go to Dave Carver. Dave has single handedly, created a JUnit version of the full W3C XPath 2.0 test suite, which is in itself a great feat! Having JUnit tests, helps us tremendously to run the XPath 2.0 tests, from within Eclipse.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;Update on 2009-08-09:&lt;/span&gt; Following are the current PsychoPath test data:&lt;br /&gt;Total tests: 8137&lt;br /&gt;Failures: 386&lt;br /&gt;Errors: 24&lt;br /&gt;This reflects a test suite pass percentage of about, 95% which looks very impressive. The test suite code coverage, is about 75-80%.&lt;br /&gt;Lot of credit for the latest PsychoPath improvements should go to, "Jesper S Møller" who has recently volunteered to help improve PsychoPath with the XPath 2.0 test suite. Dave Carver is also putting in his time, on PsychoPath improvements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6665802822234276446?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6665802822234276446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6665802822234276446' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6665802822234276446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6665802822234276446'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/07/eclipse-psychopath-xpath-20-processor.html' title='PsychoPath XPath 2.0 processor update'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8307114067128695962</id><published>2009-06-26T06:33:00.004+05:30</published><updated>2009-09-27T21:34:28.788+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='oo'/><title type='text'>Multiple inheritance in Java</title><content type='html'>I have always missed true multiple inheritance in Java (like, in C++). For e.g., we are not able to define a class as follows in Java:&lt;br /&gt;&lt;br /&gt;class X extends A, B, C {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Though, I do not see any inheritance use case which cannot be solved by the current Java facilities, but I would love to have this facility in Java. I think, the most latest Java version (1.7) doesn't have this feature.&lt;br /&gt;&lt;br /&gt;One workaround I can see, for multiple inheritance, is to define a class like following:&lt;br /&gt;&lt;br /&gt;class X {&lt;br /&gt;A a;&lt;br /&gt;B b;&lt;br /&gt;C c;  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;i.e., we could create private class members inside X (whose functionality we want to use in class X).&lt;br /&gt;&lt;br /&gt;Though this might serve purpose for some of the cases, but it's not true multiple inheritance! This I think, is actually aggregation pattern.&lt;br /&gt;&lt;br /&gt;Of course, Java has multiple inheritance of interfaces. But that is inheritance of method signatures, and not of implementation.&lt;br /&gt;&lt;br /&gt;I guess, keeping the number of base classes to one, Java is much simpler syntactically, and has a simpler compiler implementation. Though I agree, that having a simple syntax (as the current Java inheritance facilities) which is powerful enough, and can solve many use cases is better, than having a complex syntactical facility, which might serve even more uses cases, but could also lead to semantically difficult programs, which may be difficult to maintain and debug, as complexity of the problem domain increases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8307114067128695962?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8307114067128695962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8307114067128695962' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8307114067128695962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8307114067128695962'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/06/multiple-inheritance-in-java.html' title='Multiple inheritance in Java'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5068872218902381758</id><published>2009-06-21T09:56:00.005+05:30</published><updated>2010-05-01T05:39:40.345+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='java'/><category scheme='http://www.blogger.com/atom/ns#' term='theory'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><title type='text'>Primitive long a subtype of float</title><content type='html'>The Java language specification defines, that primitive "long" is a subtype of primitive "float" (ref, &lt;a href="http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.10.1"&gt;http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.10.1&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;But XML Schema Datatypes spec, shows no relationship between xs:float and xs:long (&lt;br /&gt;ref: &lt;a href="http://www.w3.org/TR/xmlschema-2/#built-in-datatypes"&gt;XML Schema 1.0 data types&lt;/a&gt;, &lt;a href="http://www.w3.org/TR/xmlschema11-2/#built-in-datatypes"&gt;XML Schema 1.1 data types&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;I'm a little confused, that which concept is correct (Java's definition of this data-type inheritance, or XML Schema). I seem to be in favor of XML Schema definition. But perhaps, XML Schema type system is for XML oriented data, and Java type system is for a wider class of applications. But I'm not sure, if this is the reason for the differences of definitions in Java language spec and XML Schema.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5068872218902381758?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5068872218902381758/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5068872218902381758' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5068872218902381758'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5068872218902381758'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/06/primitive-long-subtype-of-float.html' title='Primitive long a subtype of float'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2616943899180484496</id><published>2009-06-20T14:47:00.006+05:30</published><updated>2009-06-20T15:09:18.218+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Became Eclipse WTP committer</title><content type='html'>I was nominated as &lt;a href="http://www.eclipse.org/webtools/"&gt;Eclipse WTP&lt;/a&gt; project committer, for the &lt;a href="http://www.eclipse.org/webtools/sse/"&gt;WTP Source Editing&lt;/a&gt; subproject.&lt;br /&gt;&lt;br /&gt;As per the voting process, for becoming an Eclipse project committer, the Eclipse WTP Source Editing team, granted me project committership on 18, Jun 2009.&lt;br /&gt;&lt;br /&gt;My contributions to PsychoPath XPath 2.0 engine (which is one of the components in WTP Source Editing tooling), helped me become a committer to this project.&lt;br /&gt;&lt;br /&gt;I am happy to be included in the Eclipse WTP team. I look forward to contribute more to PsychoPath, and other WTP components. Apart from PsychoPath, I look forward to work on WTP XSL components in near future.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2616943899180484496?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2616943899180484496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2616943899180484496' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2616943899180484496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2616943899180484496'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/06/became-eclipse-wtp-committer.html' title='Became Eclipse WTP committer'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5452268687747542407</id><published>2009-06-15T18:17:00.007+05:30</published><updated>2009-06-15T21:01:32.827+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Running first XSLT 2.0 stylesheet with IBM XSLT 2.0 engine</title><content type='html'>I could run my first &lt;a href="http://www.w3.org/TR/xslt20/"&gt;XSLT 2.0&lt;/a&gt; stylesheet with IBM XSLT 2.0 engine (ref, &lt;a href="http://webspherecommunity.blogspot.com/2009/04/was-open-xml-feature-pack-beta.html"&gt;WAS XML Feature Pack Open Beta&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;I tried the following XSLT 2.0 stylesheet, using xsl:for-each-group instruction, which worked well with the IBM XSLT engine.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version="1.0"?&amp;gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                version="2.0"&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;xsl:template match="books"&amp;gt;&lt;br /&gt;     &amp;lt;books&amp;gt;&lt;br /&gt;       &amp;lt;xsl:for-each-group select="book" group-by="author"&amp;gt;&lt;br /&gt;   &amp;lt;author name="{current-grouping-key()}"&amp;gt;&lt;br /&gt;      &amp;lt;xsl:for-each select="current-group()"&amp;gt;&lt;br /&gt;        &amp;lt;book&amp;gt;&lt;br /&gt;          &amp;lt;xsl:copy-of select="name" /&amp;gt;&lt;br /&gt;   &amp;lt;xsl:copy-of select="publisher" /&amp;gt;&lt;br /&gt;        &amp;lt;/book&amp;gt;&lt;br /&gt;      &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;   &amp;lt;/author&amp;gt;&lt;br /&gt;       &amp;lt;/xsl:for-each-group&amp;gt;&lt;br /&gt;     &amp;lt;/books&amp;gt;&lt;br /&gt;  &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5452268687747542407?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5452268687747542407/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5452268687747542407' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5452268687747542407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5452268687747542407'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/06/running-first-xslt-20-stylesheet-with.html' title='Running first XSLT 2.0 stylesheet with IBM XSLT 2.0 engine'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5842924732410127450</id><published>2009-06-13T20:57:00.006+05:30</published><updated>2010-05-30T14:36:41.445+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>XML Schema validation with Xerces-J</title><content type='html'>Hiranya Jayathilaka raised an interesting discussion some time ago on xerces-dev list, that how we could validate an XML Schema 1.0 document using Xerces-J. Hiranya was looking for a solution using a Java API with Xerces-J. We were looking for verifying the correctness of the Schema document, and not doing an XML instance document validation.&lt;br /&gt;&lt;br /&gt;I'm providing a summary of the discussion we had on the list, and the conclusions we made.&lt;br /&gt;&lt;br /&gt;There are basically three ways of doing this:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;1. Using a JAXP SchemaFactory&lt;/span&gt;&lt;br /&gt;Using this technique, we do something like below:&lt;br /&gt;&lt;br /&gt;SchemaFactory sf = SchemaFactory.newInstance ..&lt;br /&gt;sf.setErrorHandler ..&lt;br /&gt;Schema s = sf.newSchema(new StreamSource(schemapath));&lt;br /&gt;&lt;br /&gt;The 'SchemaFactory.newSchema' call would not succeed if XML Schema has a grammar error.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;2. Using XSLoader&lt;/span&gt;&lt;br /&gt;Using this technique, we do something like below:&lt;br /&gt;&lt;br /&gt;XSLoaderImpl xsLoader = new XSLoaderImpl();&lt;br /&gt;XSModel xsModel = xsLoader.loadURI(xsdUri);&lt;br /&gt;&lt;br /&gt;Michael Glavassevich suggested, how we could add an error handler to this mechanism:&lt;br /&gt;&lt;br /&gt;DOMErrorHandler myErrorHandler = ...;&lt;br /&gt;&lt;br /&gt;XSImplementation xsImpl = (XSImplementation) registry.getDOMImplementation("XS-Loader");&lt;br /&gt;XSLoader xsLoader = xsImpl.createXSLoader(null);&lt;br /&gt;&lt;br /&gt;DOMConfiguration config = xsLoader.getConfig();&lt;br /&gt;config.setParameter("error-handler", myErrorHandler); // &amp;lt;-- set the error handler&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;3. Using XMLGrammarPreparser&lt;/span&gt;&lt;br /&gt;Using this technique, we do something like below (thanks to  Hiranya Jayathilaka for sharing this code):&lt;br /&gt;&lt;br /&gt;XMLGrammarPreparser preparser = new XMLGrammarPreparser();&lt;br /&gt;preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);&lt;br /&gt;preparser.setFeature("http://xml.org/sax/features/namespaces", true);&lt;br /&gt;preparser.setFeature("http://xml.org/sax/features/validation", true);&lt;br /&gt;preparser.setFeature("http://apache.org/xml/features/validation/schema", true);&lt;br /&gt;preparser.setErrorHandler(new MyErrorHandler());&lt;br /&gt;Grammar g = preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA, new XMLInputSource(null, xsdUrl, null));&lt;br /&gt;&lt;br /&gt;Michael Glavassevich provided a nice comparison of these three approaches:&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;SchemaFactory&lt;/span&gt; - it is an entry point into the JAXP Validation API for loading schemas for validation. If it was a user asking I'd recommend SchemaFactory of the three choices since it's in Java 5+ and would work in environments where Xerces isn't available.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;XSLoader&lt;/span&gt;- it is an entry point into the XML Schema API for obtaining an XSModel for analysis/processing of the component model.&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;XMLGrammarPreparser&lt;/span&gt; - it provides API for preparsing schemas and DTDs for use in grammar caching (i.e. a lower-level alternative to SchemaFactory).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5842924732410127450?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5842924732410127450/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5842924732410127450' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5842924732410127450'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5842924732410127450'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/06/xml-schema-validation-with-xerces-j.html' title='XML Schema validation with Xerces-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1340618549517051688</id><published>2009-05-30T11:22:00.001+05:30</published><updated>2009-06-21T10:17:56.301+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='theory'/><title type='text'>Function parameters vs global variables</title><content type='html'>I bumped upon this problem, and thought of sharing my experiences here.&lt;br /&gt;&lt;br /&gt;There are occasions, where I have to write an XSLT function and simply use it. For e.g. (this is just an illustration. we could have more function parameters, and a different return type),&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;xsl:function name="fn:somefunction" as="xs:boolean"&amp;gt;&lt;br /&gt;  &amp;lt;xsl:param name="pName" as="xs:string" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;!-- use $pName and the variable, $someList (defined below) --&amp;gt;&lt;br /&gt;  &amp;lt;xsl:sequence select="something.." /&amp;gt;&lt;br /&gt;&amp;lt;/xsl:function&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The evaluation of this function also depends on some data/information other than the parameters being passed. This external information on which the function depends, could be a global variable. Say for e.g.,&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;xsl:variable name="someList" as="element()+"&amp;gt;&lt;br /&gt;  &amp;lt;x&gt;a&amp;lt;/x&amp;gt;&lt;br /&gt;  &amp;lt;x&gt;b&amp;lt;/x&amp;gt;&lt;br /&gt;  ..&lt;br /&gt;  ..&lt;br /&gt;&amp;lt;/xsl:variable&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In my case, this is a fairly static data (the variable, $someList), and is needed for the evaluation of above function.&lt;br /&gt;&lt;br /&gt;I could see two option, on how the function may use an external data ($someList in this case):&lt;br /&gt;1) Have an external data as a global variable (as illustrated above)&lt;br /&gt;2) Supply this data as additional function parameter&lt;br /&gt;&lt;br /&gt;I was in a sort of dilemma recently, where I had to decide whether I should go for option 1) or 2).&lt;br /&gt;&lt;br /&gt;In my case, I opted for option 1) i.e., the global variable.&lt;br /&gt;&lt;br /&gt;I can think of few pros and cons of both of the above options:&lt;br /&gt;1. &lt;span style="font-style:italic;"&gt;Having a global variable:&lt;/span&gt; This is good, if the external information is fairly static and perhaps has big chunk of data. Having global variable could be also useful, if the data is shared between multiple functions.&lt;br /&gt;2. &lt;span style="font-style:italic;"&gt;Having a parameter for the data:&lt;/span&gt; This option looks good from the point of view of the principle of &lt;a href="http://en.wikipedia.org/wiki/Composability"&gt;composability&lt;/a&gt;. Functional programming advocates like this idea. I think, in classical computer science theory, a function (a callable module) is an abstraction which takes some input and produces some output. I think, the notion of functions accessing data which exists outside it's body is a mechanism devised by specific programming languages, and not as such defined by computer science theory. So from the point of view of this idea, having parameter for data is a good option. In fact I would also support this option, as far as possible.&lt;br /&gt;&lt;br /&gt;In my case, I was working with XSLT. But I guess, these concepts would apply to many of other programming languages as well.&lt;br /&gt;&lt;br /&gt;This topic could turn into a discussion, about how we must write good computer programs.&lt;br /&gt;&lt;br /&gt;Any ideas are welcome please.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1340618549517051688?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1340618549517051688/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1340618549517051688' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1340618549517051688'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1340618549517051688'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/05/function-parameters-vs-global-variables.html' title='Function parameters vs global variables'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2856528918370383451</id><published>2009-05-26T02:31:00.001+05:30</published><updated>2010-03-07T09:36:23.006+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>PsychoPath XPath 2.0 processor update</title><content type='html'>We recently implemented quite a few built in XSD numeric data types in PsychoPath XPath 2.0 processor (ref, &lt;a href="http://www.w3.org/TR/xmlschema-2/#built-in-datatypes"&gt;http://www.w3.org/TR/xmlschema-2/#built-in-datatypes&lt;/a&gt;). Now all (I mean, really all of xs:decimal ones :)) the data types in the xs:decimal hierarchy are available in PsychoPath, and these should be available in &lt;a href="http://www.eclipse.org/webtools/"&gt;Eclipse WTP&lt;/a&gt; 3.2 M1 (which should be released sometime soon after the &lt;a href="http://www.eclipse.org/"&gt;Eclipse Galileo&lt;/a&gt; release, at around June 09' end).&lt;br /&gt;&lt;br /&gt;Now almost all the major built in Schema types are available in PsychoPath, except for few subtypes of xs:string (like xs:normalizedString, xs:token etc.). These shouldn't be much difficult to add.&lt;br /&gt;&lt;br /&gt;Dave Carver reported, that the improvements we have done recently in PsychoPath have significantly improved it's compliance to the W3C XPath 2.0 test suite.&lt;br /&gt;&lt;br /&gt;PsychoPath processor version is now enhanced from 1.0 to 1.1.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2856528918370383451?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2856528918370383451/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2856528918370383451' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2856528918370383451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2856528918370383451'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/05/psychopath-xpath-20-processor-update.html' title='PsychoPath XPath 2.0 processor update'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2223616280839514724</id><published>2009-05-17T12:03:00.006+05:30</published><updated>2010-03-07T09:45:11.902+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J XSD 1.1 assertions and PsychoPath XPath 2.0 processor update</title><content type='html'>I recently contributed few patches to the Eclipse PsychoPath XPath 2.0 engine, to support Schema aware XPath (2.0) expressions. These patches would enhance Schema aware support in PsychoPath XPath2 engine, for element and attribute nodes, for the XML Schema primitive types.&lt;br /&gt;&lt;br /&gt;These enhancements in PsychoPath engine would make XPath expressions like following possible, to be&amp;nbsp;evaluated&amp;nbsp;by PsychoPath engine:&lt;br /&gt;&lt;br /&gt;person/@dob eq xs:date('2006-12-10') // if dob is an attribute, and of schema type xs:date&lt;br /&gt;&lt;br /&gt;person/dob eq xs:date('2006-12-10') // if dob is an element, and of schema type xs:date&lt;br /&gt;&lt;br /&gt;@max ge @min // this would work if 'max' and 'min' have say schema types, xs:int&lt;br /&gt;&lt;br /&gt;The patch in my local environment already exhibits these improvements. As promised by Dave Carver (the PsychoPath engine project lead), users would likely get these improvements in &lt;a href="http://www.eclipse.org/webtools/"&gt;Eclipse WTP (Web Tools Project)&lt;/a&gt; 3.2.&lt;br /&gt;2009-05-24: These changes are now committed to the Eclipse CVS server, and the improvements are flagged to be delivered in Eclipse WTP 3.2 M1, which should be quite sooner. Thanks to Dave Carver for testing all my patches, and committing them to the server.&lt;br /&gt;&lt;br /&gt;PsychoPath engine already has a framework (thanks to Andrea Bittau and his team) for supporting Schema awareness (based on the &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;&amp;nbsp;XSD schema model). I just added in small pieces of code in attribute and element node implementations (particularly, improving the "typed value" of attribute and element nodes for built in XSD schema types), to enhance schema aware support.&lt;br /&gt;&lt;br /&gt;I think, we are gradually moving to a more mature schema aware support in PsychoPath.&lt;br /&gt;&lt;br /&gt;I'm also using these new PsychoPath processor capabilities, to implement schema aware XPath 2.0 evaluations in Xerces-J XSD assertions support.&lt;br /&gt;&lt;br /&gt;I'm currently working on to construct a typed XPath data model instance, for XSD 1.1 assertions evaluations. Having this capability, would allow users to write XPath expressions like, following:&lt;br /&gt;&lt;br /&gt;@max ge @min&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;person/@dob eq xs:date('2006-12-10')&lt;br /&gt;&lt;br /&gt;In the absence of this (i.e, typed XDM nodes), currently users have to make explicit cast operations, like following:&lt;br /&gt;&lt;br /&gt;xs:int(@max) ge xs:int(@min)&lt;br /&gt;&lt;br /&gt;or&lt;br /&gt;&lt;br /&gt;xs:date(person/@dob) eq xs:date('2006-12-10')&lt;br /&gt;&lt;br /&gt;The XML Schema 1.1 assertions spec recommends a typed XDM instance.&lt;br /&gt;&lt;br /&gt;We hope to provide this capability within Xerces-J, inline with the XML Schema 1.1 assertions specification.&lt;br /&gt;&lt;br /&gt;2009-05-23: These improvements are now implemented, and I've submitted the code improvements to the Apache Xerces-J JIRA server. I'm hoping, we'll have these improvements committed on the Xerces-J SVN server some time soon.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2223616280839514724?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2223616280839514724/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2223616280839514724' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2223616280839514724'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2223616280839514724'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/05/xerces-j-assertions-and-psychopath.html' title='Xerces-J XSD 1.1 assertions and PsychoPath XPath 2.0 processor update'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-165234496762351722</id><published>2009-05-08T23:10:00.003+05:30</published><updated>2010-03-02T21:02:55.331+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Became Apache Xerces-J committer</title><content type='html'>As per the voting process for becoming an &lt;a href="http://www.apache.org/"&gt;Apache&lt;/a&gt; project committer, the Apache &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; team granted me the committer status for the Xerces-J project on May 5, 2009.&lt;br /&gt;&lt;br /&gt;This gives me an opportunity to contribute to the Xerces-J codebase, in a more direct way.&lt;br /&gt;&lt;br /&gt;It's indeed a privilege for me to be part of the core Xerces team. Starting from being an Xerces user (since long time ago :)), to becoming project committer has been a rewarding journey in numerous ways.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-165234496762351722?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/165234496762351722/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=165234496762351722' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/165234496762351722'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/165234496762351722'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/05/became-apache-xerces-j-committer.html' title='Became Apache Xerces-J committer'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8005023133535667706</id><published>2009-05-03T14:45:00.001+05:30</published><updated>2009-09-12T20:39:31.062+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Apache Xerces-J assertions implementation and PsychoPath XPath 2.0 processor</title><content type='html'>I shared sometime back on this blog, on the work I am doing regarding &lt;a href="http://mukulgandhi.blogspot.com/2009/04/xml-schema-11-assertions.html"&gt;XML Schema 1.1 assertions support in Xerces-J&lt;/a&gt;. The XML Schema 1.1 assertions processing requires a XPath 2.0 processor for performing Schema validation.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; team has opted to use the open source XPath 2.0 processor, &lt;a href="http://psychopath.sourceforge.net"&gt;PsychoPath&lt;/a&gt;. PsychoPath was developed by Andrea Bittau and his team. The PsychoPath team donated the PsychoPath code base to Eclipse community, where it is now formally used in the &lt;a href="http://www.eclipse.org/webtools/"&gt;Eclipse, Web Tools Platform project&lt;/a&gt;. Future enhancements to PsychoPath are now taking place at Eclipse.&lt;br /&gt;&lt;br /&gt;Since Xerces-J is using PsychoPath XPath 2.0 engine, we wish that PsychoPath be ideally 100% compliant to the XPath 2.0 specification, so Xerces-J users can use much of the failities of the XPath 2.0 language while using XML Schema 1.1 assertions.&lt;br /&gt;&lt;br /&gt;After looking at the PsychoPath source code and using it quite a bit, my personal observation is, that PsychoPath has a pretty good XPath 2.0 implementation. Please refer to this &lt;a href="http://psychopath.sourceforge.net/report.pdf"&gt;documentation&lt;/a&gt; for knowing more about PsychoPath and the current compliance status.&lt;br /&gt;&lt;br /&gt;The Eclipse WTP team is working actively to solve any remaining non-compliant items in PsychoPath. Incidentally, I have been working recently to help improve PsychoPath's compliance to the XPath 2.0 spec, and have contributed few patches to Eclipse.&lt;br /&gt;&lt;br /&gt;We are also planning to run the W3C XPath 2.0 test suite on PsychoPath, and targetting PsychoPath to pass the test suite, with 100% coverage. This should give the PsychoPath adopters more confidence while using it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8005023133535667706?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8005023133535667706/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8005023133535667706' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8005023133535667706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8005023133535667706'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/05/xerces-j-assertions-implementation-and.html' title='Apache Xerces-J assertions implementation and PsychoPath XPath 2.0 processor'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3811586243225176976</id><published>2009-04-23T12:07:00.001+05:30</published><updated>2010-05-01T05:34:19.048+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xquery'/><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><category scheme='http://www.blogger.com/atom/ns#' term='web'/><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>WAS XML Feature Pack Open Beta</title><content type='html'>There was an annoucement recently from IBM (&lt;a href="http://webspherecommunity.blogspot.com/2009/04/was-open-xml-feature-pack-beta.html"&gt;http://webspherecommunity.blogspot.com/2009/04/was-open-xml-feature-pack-beta.html&lt;/a&gt;), about availability of "WAS XML Feature Pack Open Beta" supporting XPath 2.0, XSLT 2.0 and XQuery 1.0. It was good to know this.&lt;br /&gt;&lt;br /&gt;Therefore, users would be able to use XPath 2.0, XSLT 2.0 and XQuery 1.0 in a WAS environment, using IBM's own processors for these languages.&lt;br /&gt;&lt;br /&gt;This is an early preview release, with more enhancements expecting to come later.&lt;br /&gt;&lt;br /&gt;I'm looking forward to try these language processors myself.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3811586243225176976?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3811586243225176976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3811586243225176976' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3811586243225176976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3811586243225176976'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/04/was-xml-feature-pack-open-beta.html' title='WAS XML Feature Pack Open Beta'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-2840037684291895852</id><published>2009-04-21T22:14:00.006+05:30</published><updated>2010-03-07T09:45:11.903+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Xerces-J: XML Schema 1.1 assertions support</title><content type='html'>This post is related to my earlier blog post, &lt;a href="http://mukulgandhi.blogspot.com/2008/07/assertions.html"&gt;http://mukulgandhi.blogspot.com/2008/07/assertions.html&lt;/a&gt; about the&amp;nbsp;&lt;a href="http://www.w3.org/TR/xmlschema11-1/#cAssertions"&gt;XML Schema 1.1 assertions&lt;/a&gt; implementation into &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Today, I reached an important milestone with all the development finished for assertions in Xerces-J, and submitted an Apache JIRA issue for review.&lt;br /&gt;&lt;br /&gt;Here is a small example of what XML Schema 1.1 assertions means:&lt;br /&gt;&lt;pre&gt;&amp;lt;xs:complexType name="book"&amp;gt;&lt;br /&gt;    &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="name" type="xs:string" /&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="author" type="xs:string" /&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="price" type="xs:string" /&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="publisher" type="xs:string" /&amp;gt;&lt;br /&gt;      &amp;lt;xs:element name="pub-date" type="xs:date" /&amp;gt; &lt;br /&gt;    &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;  &lt;span style="font-weight: bold;"&gt;  &lt;/span&gt;&lt;span class="Apple-style-span" style="color: orange;"&gt;&amp;lt;xs:assert test="ends-with(price, 'USD')" /&amp;gt;&lt;br /&gt;    &amp;lt;xs:assert test="pub-date &amp;gt; xs:date('2007-12-31')" /&amp;gt;&lt;/span&gt;&lt;br /&gt;  &amp;lt;/xs:complexType&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;With this XML Schema 1.1 fragment, the user wants to have a validation constraint that, the price string should end with literal 'USD' and pub-date should be greater than the date 2007-12-31. This is a very simple example, but it does signify the usefulness of assertions syntax. We could have unlimited (0-n) numbers of xs:assert elements in a XSD schema type (which could be a simple type or a complex type. Though the assertions facet name in simple types is named xs:assertion). The value of 'test' attribute in assertions is an &lt;a href="http://www.w3.org/TR/xpath20/"&gt;XPath 2.0&lt;/a&gt; expression. All the assertions have to evaluate to boolean, "true" for an element to be locally valid.&lt;br /&gt;&lt;br /&gt;There could be many other scenarios (and some of them quite complex, like for e.g., assertions present in a Schema type hierarchy) for writing assertions in XML Schema 1.1. It's difficult to specify all of them here. I'd ask the reader, to read the article [2] below, for learning about many of other, XML Schema 1.1 assertions scenarios.&lt;br /&gt;&lt;br /&gt;With assertions in XML Schema 1.1 language, we could express much more involved XML validation constraints, that were almost impossible to specify in XML Schema 1.0. Using assertions, we can specify relationships between elements (like element names, contents etc), between elements and attributes, between attributes, and perhaps much more.&lt;br /&gt;&lt;br /&gt;The assertions processing in XML Schema 1.1 works as follows:&lt;br /&gt;When a XML Schema (1.1) processor encounters an element in the XML instance document, it must validate the element (if the user has requested validation) with it's associated type in the Schema (which could be a simple type or a complex type). The element's type declaration could be anonymous, or it could be a named type (which has a "name" attribute, and they are globally defined in the schema) declaration in the Schema. The XML Schema processor builds a XPath data model (XDM) tree rooted at this element (with Xerces, a XDM tree is built only if any assertions (which could be, 1-n in numbers) are associated with an element's type. If schema types of XML attributes have assertion facets, then these assertion facets work upon the attribute's value, and no XDM tree is constructed in this case). The XDM tree consists of the root element, it's attributes and all it's descendants. When an element validation is going on within Xerces, assertions evaluation also takes place as part of the validation process. Each assertion is evaluated on the XDM tree rooted at a given context element. Therefore, also any attempt by the assert XPath expression to access any node outside this element tree will not succeed.&lt;br /&gt;&lt;br /&gt;We also have a wiki page for Xerces assertions implementation, &lt;a href="http://wiki.apache.org/xerces/XML_Schema_1.1_Assertions"&gt;http://wiki.apache.org/xerces/XML_Schema_1.1_Assertions&lt;/a&gt;. It describes a bit of implementation details of assertions in Xerces.&lt;br /&gt;&lt;br /&gt;I'm happy to share that we expect Xerces-J to support the whole of assertions implementation in a near future release. And of course, Xerces would support lot of other XML Schema 1.1 features as well.&lt;br /&gt;&lt;br /&gt;Following are few nice articles related to XML Schema 1.1, which are worth reading:&lt;br /&gt;1. &lt;a href="http://www.ibm.com/developerworks/xml/library/x-xml11pt1/"&gt;Overview of XML Schema 1.1 language&lt;/a&gt;&lt;br /&gt;2. &lt;a href="http://www.ibm.com/developerworks/library/x-xml11pt2/"&gt;XML Schema 1.1 co-occurence constraints using XPath 2.0&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-2840037684291895852?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/2840037684291895852/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=2840037684291895852' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2840037684291895852'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/2840037684291895852'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/04/xml-schema-11-assertions.html' title='Xerces-J: XML Schema 1.1 assertions support'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3893378701160524159</id><published>2009-03-20T22:15:00.000+05:30</published><updated>2009-03-21T09:10:46.623+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Data modeling approaches</title><content type='html'>With reference to my earliest blog post on "Relational/XML hybrid database design",&lt;br /&gt;&lt;a href="http://mukulgandhi.blogspot.com/2009/01/relationalxml-hybrid-database-design.html"&gt;http://mukulgandhi.blogspot.com/2009/01/relationalxml-hybrid-database-design.html&lt;/a&gt;,&lt;br /&gt;&lt;br /&gt;I have some more thoughts on this topic.&lt;br /&gt;&lt;br /&gt;I think, an information model of an enterprise should consider XML as a first class data storage mechanism, along side the relational mechanism.&lt;br /&gt;&lt;br /&gt;When XML was not there, using relational storage (and some other forms of EIS data) was the only choice. Given the benefits of XML (some of which are mentioned in my previous blog post cited above), it should be considered equally important as the relational mechanism, for data persistence needs.&lt;br /&gt;&lt;br /&gt;There should be a mixture of XML and relational data in the overall data model of an enterprise. This would bring best of the worlds of relational and XML storage, to the enterprise's data.&lt;br /&gt;&lt;br /&gt;I have seen that, today XML is used a lot for various kinds of property/configuration files, and for sending messages. But I feel, that wherever it makes good business sense, the core business entities should be modeled as XML along side the relational models. With the current hybrid XML/Relational databases (like, DB2 with pureXML), we can have the relational and XML data in the same transactional context.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3893378701160524159?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3893378701160524159/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3893378701160524159' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3893378701160524159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3893378701160524159'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/03/data-modeling-approaches.html' title='Data modeling approaches'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3372772185207673510</id><published>2009-02-28T17:11:00.000+05:30</published><updated>2009-03-07T07:33:18.238+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='theory'/><title type='text'>Ptarithmetic: logic in computer science</title><content type='html'>A post on comp.theory newsgroup referred to this &lt;a href="http://arxiv.org/abs/0902.2969"&gt;paper&lt;/a&gt;, by &lt;a href="http://www.csc.villanova.edu/~japaridz/"&gt;Giorgi Japaridze&lt;/a&gt;. I read a bit of this paper, and believe the thoughts presented here are quite promising (at least, I found the goal of this study quite ambitious). I guess, people with interest in computer logic might find this interesting.&lt;br /&gt;&lt;br /&gt;This paper introduces ptarithmetic (short for "polynomial time arithmetic") - a formal number theory similar to the well known &lt;a href="http://en.wikipedia.org/wiki/Peano_arithmetic"&gt;Peano arithmetic&lt;/a&gt;, but based on the recent, &lt;a href="http://www.cis.upenn.edu/~giorgi/cl.html"&gt;computability logic&lt;/a&gt; instead of classical logic.&lt;br /&gt;&lt;br /&gt;The arithmetic primitives defined in this theory, compute in polynomial time (as against classical logic, operations in which can compute in exponential or combinatorial time).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3372772185207673510?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3372772185207673510/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3372772185207673510' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3372772185207673510'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3372772185207673510'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/02/ptarithmetic-logic-in-computer-science.html' title='Ptarithmetic: logic in computer science'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5417460087072989139</id><published>2009-02-28T11:57:00.000+05:30</published><updated>2009-02-28T17:04:58.168+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='theory'/><title type='text'>An ideal compiler architecture</title><content type='html'>I found the compiler architecture description here, &lt;a href="http://lambda.uta.edu/cse5317/notes/node5.html"&gt;http://lambda.uta.edu/cse5317/notes/node5.html&lt;/a&gt; to be the most appealing from all the definitions I have read upto now.&lt;br /&gt;&lt;br /&gt;Particularly I like the following idea:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-style:italic;"&gt;"Suppose that you want to build compilers for n programming languages (eg, FORTRAN, C, C++, Java, BASIC, etc) and you want these compilers to run on m different architectures (eg, MIPS, SPARC, Intel, alpha, etc). If you do that naively, you need to write n*m compilers, one for each language-architecture combination.&lt;br /&gt;&lt;br /&gt;The holly grail of portability in compilers is to do the same thing by writing n + m programs only. How? You use a universal Intermediate Representation (IR) and you make the compiler a two-phase compiler. An IR is typically a tree-like data structure that captures the basic features of most computer architectures. The first phase of this compilation scheme, called the front-end, maps the source code into IR, and the second phase, called the back-end, maps IR into machine code. That way, for each programming language you want to compile, you write one front-end only, and for each computer architecture, you write one back-end. So, totally you have n + m components."&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Though the above idea of compiler construction is quite ideal, the author cautions with these statements:&lt;br /&gt;&lt;br /&gt;"But the above ideal separation of compilation into two phases does not work very well for real programming languages and architectures. Ideally, you must encode all knowledge about the source programming language in the front end, you must handle all machine architecture features in the back end, and you must design your IRs in such a way that all language and machine features are captured properly."&lt;br /&gt;&lt;br /&gt;I guess, this is something interesting to think about. How good it will be, if all major programming languages translate to the same intermediate representation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5417460087072989139?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5417460087072989139/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5417460087072989139' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5417460087072989139'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5417460087072989139'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/02/ideal-compiler-architecture.html' title='An ideal compiler architecture'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8510738880609693319</id><published>2009-02-21T09:56:00.001+05:30</published><updated>2009-06-28T21:23:48.439+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='web'/><title type='text'>Some thoughts about IPv6</title><content type='html'>I read an article at &lt;a href="http://www.iana.org/"&gt;IANA&lt;/a&gt; about the current state of &lt;a href="http://en.wikipedia.org/wiki/IPv6"&gt;IPv6&lt;/a&gt; implementation on the world wide internet. I just thought of sharing few points here, as mentioned in the IANA IPv6 report, to help spread some awareness about this important issue. The article presents following facts:&lt;br /&gt;&lt;br /&gt;1. &lt;a href="http://en.wikipedia.org/wiki/IPv4"&gt;IPv4&lt;/a&gt; (the current traditional sceme of IP address allocation) theoretically has address space of about 4-5 billion IP addresses. When this scheme was designed, when the modern internet came into existence, it was imagined that about 4-5 billion devices will be a good maximum limit to the number of devices which can be connected to the internet.&lt;br /&gt;&lt;br /&gt;But with the growing popularity of the internet across the world, the IPv4 scheme has proved to be insufficient to scale the internet using new devices. By Oct 2007, only 17% IP addresses were available for allocation under IPv4 scheme. Somewhere in 2010-11, all the IPv4 addresses will be exhausted. So after that time, it will be inevitable for the world to shift to IPv6 scheme to add more IP devices to the internet.&lt;br /&gt;&lt;br /&gt;Apart from computer machines needing to connect to internet, many different kind of devices are now being designed to have IP capability (like many home appliances for example). To be able to assign all these new devices the globally unique IP addresses, adoption of IPv6 is bound to take place.&lt;br /&gt;&lt;br /&gt;2. During the transition period from IPv4 to IPv6, both IPv4 and IPv6 hosts can continue to coexist and interoperate. But interoperation of these two schemes would require investment of time and money from hardware vendors, and network service providers.&lt;br /&gt;The IPv4 scheme is expected to continue in operation for couple of years from now (I guess 5-10 years).&lt;br /&gt;&lt;br /&gt;3. The IPv6 support in the softwares seems not to be a problem. Major OS vendors already have IPv6 support built into the OSs. The challenging aspect is the IPv6 support from the hardware and network equipment providers. I am sure that hardware and network vendors who intend to be be in the internet business for a long time in future, will commit the time and money to bring this vital expansion of the internet.&lt;br /&gt;&lt;br /&gt;Interestingly, JDK 1.4 and above has provided support for &lt;a href="http://java.sun.com/j2se/1.4.2/docs/api/java/net/Inet6Address.html"&gt;IPv6 based IP addresses&lt;/a&gt;. So writing IPv6 enabled client applications is already possible with Java JDK.&lt;br /&gt;&lt;br /&gt;Google is also serious about IPv6 adoption. The google search service is now available for IPv6 enabled devices. Please refer, &lt;a href="http://googleblog.blogspot.com/2008/05/looking-towards-ipv6.html"&gt;http://googleblog.blogspot.com/2008/05/looking-towards-ipv6.html&lt;/a&gt; for more information about Google's efforts to promote IPv6 scheme. &lt;a href="http://ipv6.google.com/"&gt;http://ipv6.google.com/&lt;/a&gt; is the web URL to do google search from IPv6 machines. If you do a google search from an IPv4 machine (as I do, from the IP address 192.168.1.8) to this host, you'll get an "unknown host error". The machine should have an IPv6 based IP address to access this search service from Google.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8510738880609693319?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8510738880609693319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8510738880609693319' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8510738880609693319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8510738880609693319'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/02/update-on-ipv6.html' title='Some thoughts about IPv6'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3530387104986883696</id><published>2009-02-11T22:24:00.000+05:30</published><updated>2009-02-22T21:59:15.594+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>DOM vs JAXB</title><content type='html'>The &lt;a href="http://www.w3.org/DOM/DOMTR"&gt;DOM&lt;/a&gt; API and &lt;a href="https://jaxb.dev.java.net/"&gt;JAXB&lt;/a&gt; (Java Architecture for XML Binding) look a bit similar to me, for the task of mapping Java objects to XML documents (the concept popularly known as, XML data binding).&lt;br /&gt;&lt;br /&gt;JAXB essentially does [1],&lt;br /&gt;&lt;br /&gt;1. Marshalling of Java objects to XML.&lt;br /&gt;&lt;br /&gt;2. Unmarshalling of the XML data to Java objects.&lt;br /&gt;&lt;br /&gt;The DOM API also does [2],&lt;br /&gt;&lt;br /&gt;1. Transformation of DOM tree to XML (known as the XML serialization process).&lt;br /&gt;&lt;br /&gt;2. Transforming of XML documents to a DOM object tree.&lt;br /&gt;&lt;br /&gt;At a broad level, the approaches [1] and [2] look similar.&lt;br /&gt;&lt;br /&gt;But according to me, following are the differences between the two approaches:&lt;br /&gt;&lt;br /&gt;1. The JAXB transformation is driven by a Schema. The JAXB binding compiler generates Java type definitions for the Schema components. With JAXB, the object model (generated by the JAXB framework) maps closely to the concepts in the problem domain (for e.g, there will be a Java class PurchaseOrder corresponding to a Schema type PurchaseOrder).&lt;br /&gt;&lt;br /&gt;Whereas with DOM, the Schema does not drive the XML and Java mapping. And, all the elements in an XML document map to the DOM class, org.w3c.dom.Element. The name of the element, the data inside it and other properties of the element are accessible using the methods provided by the DOM API.&lt;br /&gt;&lt;br /&gt;2. There are perhaps some performance differences between JAXB and DOM. A study about this has been done by Santiago Pericas-Geertsen, as shared in these blog posts.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://weblogs.java.net/blog/spericas/archive/2005/12/dom_vs_jaxb_per.html"&gt;http://weblogs.java.net/blog/spericas/archive/2005/12/dom_vs_jaxb_per.html&lt;/a&gt;&lt;br /&gt;&lt;a href="http://weblogs.java.net/blog/spericas/archive/2005/12/dom_vs_jaxb_per_1.html"&gt;http://weblogs.java.net/blog/spericas/archive/2005/12/dom_vs_jaxb_per_1.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Under certain circumstances (to my opinion), the XML data bindings needs can be met by the DOM API (where a Schema does not drive the data binding process, and a raw mapping of XML and Java is required).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3530387104986883696?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3530387104986883696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3530387104986883696' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3530387104986883696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3530387104986883696'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/02/dom-vs-jaxb.html' title='DOM vs JAXB'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4438424762761050425</id><published>2009-01-26T17:21:00.000+05:30</published><updated>2009-02-22T22:05:52.893+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Relational/XML hybrid database design</title><content type='html'>Lately, I have been reading about the database design (particularly, for relational and XML hybrid storage).&lt;br /&gt;&lt;br /&gt;I felt that a column design (for complex types, like say purchase order) having XML data (like the native SQL type, 'XML') is quite useful, as compared to distributing the whole schema (say, the purchase order - PO schema) across multiple relational tables and columns (with simple types).&lt;br /&gt;&lt;br /&gt;Following are some of the advantages for using the SQL type, 'XML' in RDBMS tables:&lt;br /&gt;&lt;br /&gt;1. The database and nearly the whole application becomes shielded from the Schema changes. If say something in the PO Schema changes, we only change the PO XML Schema. The RDBMS data model need not change (the columns of the table would still be same, say a, b, po where the column po is of type 'XML'). The SQL statements in the application programs (say, the JDBC statements) also need not change.&lt;br /&gt;&lt;br /&gt;The impact of the Schema change on the application will be quite less, as compared to the situation, if the data were kept in simple type columns.&lt;br /&gt;&lt;br /&gt;2. Designing a complex type (say, a purchase order) in a 'XML' column makes good design sense. The complex type most of the times has hierarchical structure, as is XML. So it is a good design decision to design complex types as XML. This also has advantage during validation of the data during data inserts and updates. The XML data as a whole get's written to the database, and an internal schema in the database validates the incoming XML data. This is much more simpler and natural than validating the data, had it been stored in multiple tables and columns.&lt;br /&gt;&lt;br /&gt;3. The XML data in the relational/XML hybrid database can be accessed using &lt;a href="http://www.w3.org/TR/xquery/"&gt;XQuery&lt;/a&gt;, and also updated using &lt;a href="http://www.w3.org/TR/xquery-update-10/"&gt;XQuery update facility&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I found &lt;a href="http://www-01.ibm.com/software/data/db2/xml/"&gt;DB2 with pureXML&lt;/a&gt; having an excellent support for all these features.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4438424762761050425?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4438424762761050425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4438424762761050425' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4438424762761050425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4438424762761050425'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/01/relationalxml-hybrid-database-design.html' title='Relational/XML hybrid database design'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-992263315019143673</id><published>2009-01-16T21:53:00.000+05:30</published><updated>2009-01-16T22:18:02.354+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Normalizing unnecessary whitespace text nodes during XSLT transformation</title><content type='html'>Let's say that my input XML is following,&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;test&amp;gt;&lt;br /&gt;  &amp;lt;a/&amp;gt;&lt;br /&gt;  &amp;lt;b/&amp;gt;&lt;br /&gt;  &amp;lt;c/&amp;gt;&lt;br /&gt;  &amp;lt;d/&amp;gt;&lt;br /&gt;  &amp;lt;e/&amp;gt;&lt;br /&gt;  &amp;lt;f&amp;gt;some data ..&amp;lt;/f&amp;gt;&lt;br /&gt;&amp;lt;/test&amp;gt;&lt;/pre&gt;&lt;br /&gt;I need to write an XSLT transformation, which just removes elements, 'c' and 'd' and keeps rest of the structure same.&lt;br /&gt;&lt;br /&gt;The result of the transformation should be following [1]:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;test&amp;gt;&lt;br /&gt;  &amp;lt;a/&amp;gt;&lt;br /&gt;  &amp;lt;b/&amp;gt;&lt;br /&gt;  &amp;lt;e/&amp;gt;&lt;br /&gt;  &amp;lt;f&amp;gt;some data ..&amp;lt;/f&amp;gt;&lt;br /&gt;&amp;lt;/test&amp;gt;&lt;/pre&gt;&lt;br /&gt;The obvious solution to this problem is, to write a modified identity transformation logic.&lt;br /&gt;&lt;br /&gt;i.e.,&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                version="1.0"&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;xsl:template match="node() | @*"&amp;gt;&lt;br /&gt;     &amp;lt;xsl:copy&amp;gt;&lt;br /&gt;       &amp;lt;xsl:apply-templates select="node() | @*" /&amp;gt;&lt;br /&gt;     &amp;lt;/xsl:copy&amp;gt;&lt;br /&gt;   &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:template match="c | d" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;/pre&gt;&lt;br /&gt;But there is a subtle flaw in this logic. The actual output produced by the above stylesheet is,&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;test&amp;gt;&lt;br /&gt;  &amp;lt;a/&amp;gt;&lt;br /&gt;  &amp;lt;b/&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;e/&amp;gt;&lt;br /&gt;  &amp;lt;f&amp;gt;some data ..&amp;lt;/f&amp;gt;&lt;br /&gt;&amp;lt;/test&amp;gt;&lt;/pre&gt;&lt;br /&gt;There are a kind of two whitepace holes in the output (created by the elements which are removed). This makes the output not 100% same as the desired output [1].&lt;br /&gt;&lt;br /&gt;The whitespace holes in the output above can be very well explained. They are actually the newline whitespaces (near the elements 'c' and 'd') present in the original document, which are preserved in the generated output.&lt;br /&gt;&lt;br /&gt;Adding a little bit of extra logic in the stylesheet can fix this problem.&lt;br /&gt;&lt;br /&gt;The right solution will be following,&lt;pre&gt;&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                version="1.0"&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt;   &amp;lt;xsl:template match="node() | @*"&amp;gt;&lt;br /&gt;     &amp;lt;xsl:copy&amp;gt;&lt;br /&gt;       &amp;lt;xsl:apply-templates select="node() | @*" /&amp;gt;&lt;br /&gt;     &amp;lt;/xsl:copy&amp;gt;&lt;br /&gt;   &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:template match="c | d" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;   &amp;lt;xsl:template match="text()[(normalize-space() = '') and (preceding-sibling::node()[1]/self::c or preceding-sibling::node()[1]/self::d)]" /&amp;gt;&lt;br /&gt;   &lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Please note the last template in this stylesheet, which fixed the whitespaces problem for me.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-992263315019143673?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/992263315019143673/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=992263315019143673' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/992263315019143673'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/992263315019143673'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/01/normalizing-unnecessary-whitespace-text.html' title='Normalizing unnecessary whitespace text nodes during XSLT transformation'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-3071158734177908941</id><published>2009-01-10T21:48:00.000+05:30</published><updated>2009-01-11T11:38:56.375+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>XSLT functions returning void</title><content type='html'>I just thought, whether XSLT 2.0 functions can return something like a &lt;span style="font-weight:bold;"&gt;void&lt;/span&gt; value.&lt;br /&gt;&lt;br /&gt;for e.g. as we could do,&lt;br /&gt;&lt;br /&gt;public &lt;span style="font-weight:bold;"&gt;void&lt;/span&gt; myfunction() {&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;in Java.&lt;br /&gt;&lt;br /&gt;I do not think there is any syntax in XSLT which allows this declaration.&lt;br /&gt;&lt;br /&gt;i.e., can we do something like following in XSLT.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;xsl:function name="my:testfunction" as="a-void-type"&amp;gt;&lt;br /&gt;  &amp;lt;!-- something here --&amp;gt;&lt;br /&gt;&amp;lt;/xsl:function&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;I think there is no way of specifying a void type in XSLT. A function must return something. The best we could do is, that we specify the return type as, &lt;span style="font-weight:bold;"&gt;as="xs:string?"&lt;/span&gt;. i.e., the function may return a xs:string value, or it may return nothing (i.e., &lt;span style="font-weight:bold;"&gt;an empty sequence: ()&lt;/span&gt;).&lt;br /&gt;&lt;br /&gt;But if we want to return something like void from a function, we can instead implement a named template for this. i.e., something like following,&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;xsl:template name="testtemplate"&amp;gt;&lt;br /&gt;  &amp;lt;!-- something here --&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The named template is conceptually similar to xsl:function (both are callable modules), but there are some subtle differences as well, between them. xsl:function is a lot more loosely coupled module than the named template. The named template inherits the context from the caller, whereas the function has no access to the context information of the caller (though any piece of the context can be passed to the function as parameters).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-3071158734177908941?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/3071158734177908941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=3071158734177908941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3071158734177908941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/3071158734177908941'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/01/xslt-functions-returning-void.html' title='XSLT functions returning void'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7147814717316998736</id><published>2009-01-04T23:11:00.002+05:30</published><updated>2009-11-28T15:37:08.687+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>XSLT: sorting data by duration</title><content type='html'>I've this input text file (test.txt):&lt;br /&gt;&lt;br /&gt;A started at 03:12:10&lt;br /&gt;A ended at 03:20:20&lt;br /&gt;B started at 03:20:25&lt;br /&gt;B ended at 03:22:21&lt;br /&gt;C started at 03:22:23&lt;br /&gt;C ended at 03:22:55&lt;br /&gt;D started at 03:22:57&lt;br /&gt;D ended at 03:23:21&lt;br /&gt;E started at 03:23:25&lt;br /&gt;E ended at 03:24:40&lt;br /&gt;&lt;br /&gt;Here A, B, C etc. are some events, and they start at a particular time and end at another time.&lt;br /&gt;&lt;br /&gt;I need to produce an output like following:&lt;br /&gt;&lt;br /&gt;D : 0-0-24&lt;br /&gt;C : 0-0-32&lt;br /&gt;E : 0-1-15&lt;br /&gt;B : 0-1-56&lt;br /&gt;A : 0-8-10&lt;br /&gt;&lt;br /&gt;i.e., events sorted by the time they took (in ascending order of durations). The duration format in the output is, hr-min-sec.&lt;br /&gt;&lt;br /&gt;The following XSLT 2.0 stylesheet worked well for this problem,&lt;br /&gt;&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;                exclude-result-prefixes="xs"&lt;br /&gt;                version="2.0"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:output method="text" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="time-data" select="tokenize(unparsed-text('test.txt', 'UTF-8'), '\r?\n')" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:template match="/"&amp;gt;&lt;br /&gt;  &amp;lt;xsl:variable name="temp-data"&amp;gt;&lt;br /&gt;    &amp;lt;xsl:for-each select="$time-data"&amp;gt;&lt;br /&gt;      &amp;lt;xsl:variable name="val" select="normalize-space(.)" /&amp;gt;&lt;br /&gt;      &amp;lt;xsl:variable name="pos" select="position()" /&amp;gt;&lt;br /&gt;      &amp;lt;xsl:if test="position() mod 2 = 1"&amp;gt;&lt;br /&gt;        &amp;lt;data key="{tokenize($val, '\s')[1]}"&amp;gt;&lt;br /&gt;          &amp;lt;xsl:value-of select="xs:time(tokenize($time-data[$pos + 1], '\s')[last()]) -xs:time(tokenize($val, '\s')[last()])" /&amp;gt;&lt;br /&gt;        &amp;lt;/data&amp;gt;&lt;br /&gt;      &amp;lt;/xsl:if&amp;gt;&lt;br /&gt;    &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;  &amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;  &amp;lt;xsl:for-each select="$temp-data/*"&amp;gt;&lt;br /&gt;    &amp;lt;xsl:sort select="xs:dayTimeDuration(.)" /&amp;gt;&lt;br /&gt;    &amp;lt;xsl:variable name="hr" select="hours-from-duration(.)" /&amp;gt;&lt;br /&gt;    &amp;lt;xsl:variable name="min" select="minutes-from-duration(.)" /&amp;gt;&lt;br /&gt;    &amp;lt;xsl:variable name="sec" select="seconds-from-duration(.)" /&amp;gt;&lt;br /&gt;    &amp;lt;xsl:value-of select="@key" /&amp;gt; : &amp;lt;xsl:value-of select="concat($hr, '-', $min, '-', $sec)" /&amp;gt; &amp;lt;xsl:text&amp;gt;&amp;#xa;&amp;lt;/xsl:text&amp;gt;&lt;br /&gt;  &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;/pre&gt;&lt;br /&gt;The following XSLT sort instruction worked, well for this use case:&lt;br /&gt;&amp;lt;xsl:sort select="xs:dayTimeDuration(.)" order="descending" /&amp;gt;&lt;br /&gt;&lt;br /&gt;I've used Saxon to solve this.&lt;br /&gt;&lt;br /&gt;If anybody bumps by this post, and could think of a better solution (particularly written in a more functional style, and avoiding the temporary tree), I would be very glad to know that.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7147814717316998736?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7147814717316998736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7147814717316998736' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7147814717316998736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7147814717316998736'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2009/01/xslt-sorting-by-duration.html' title='XSLT: sorting data by duration'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5417822065707012461</id><published>2008-12-28T16:59:00.001+05:30</published><updated>2009-12-19T15:21:11.411+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>A static code quality tool, for XSLT code</title><content type='html'>I wrote a little tool to measure and enhance the code quality, of XSLT programs/scripts. It's available at, &lt;a href="http://gandhimukul.tripod.com/xslt/xslquality.html"&gt;http://gandhimukul.tripod.com/xslt/xslquality.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I hope that the XSLT community might find this useful.&lt;br /&gt;&lt;br /&gt;Any comments/suggestions about this tool would be most welcome.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5417822065707012461?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5417822065707012461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5417822065707012461' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5417822065707012461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5417822065707012461'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/12/static-code-quality-tool-for-xslt-code.html' title='A static code quality tool, for XSLT code'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7268961900154751223</id><published>2008-12-13T23:13:00.000+05:30</published><updated>2008-12-14T11:02:06.183+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Michael Kay on application processing</title><content type='html'>Roger L. Costello summarized an interesting discussion we had on xml-dev list, citing Michael Kay's thoughts (just thought of sharing with the readers here):&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;What language(s) do you recommend using for application processing?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;... do everything using XML-based processing languages (XSLT and XQuery).&lt;br /&gt;&lt;br /&gt;The idea I'm pushing is that you write the application end-to-end using XML-based languages. That means that you never convert the data into C++ or Java data types. If you only go half way, by calling XQuery from Java and then converting the results to Java values, you lose half the benefits.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;By "write the application end-to-end using XML-based languages" do you mean XML end-to-end or PSVI end-to-end?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;I'm not too fussed how the XML is represented, the important thing is to avoid converting it unnecessarily into non-XML models such as Java objects or SQL tables. Where "unnecessarily" means "except as required by the need to interface with other applications".&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;Isn't XSLT a special-purpose programming language?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;It's true that XSLT is a specialized language rather than a general-purpose language. But it's capable of a lot more than some people imagine. Some people never really get below the surface to discover its depth.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;What's wrong with using a mix of XML-based processing languages and imperative languages (Java, C++, etc)?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;[If you use a mix of languages then you end up] spending 75% of your programming effort converting your data between one type system and another.&lt;br /&gt;&lt;br /&gt;Writing your application in a single language, if you can do it, will always give you a substantial reduction in complexity versus using multiple languages.&lt;br /&gt;&lt;br /&gt;And writing in a language that is well adapted to the data it is required to process will save you a lot of effort (human and machine effort) in doing data conversion.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;Aren't there some applications for which an imperative language is needed? Aren't some problems so complex that they need an imperative language?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;There are no applications that NEED imperative programming (functional programming has provably the same computational power). Whether things are more EASILY done that way is in large measure a matter of your skills and experience. (I remember working with programmers from an older generation who claimed coding was easier if they used GOTO statements.) There are one or two things I still find easier in imperative languages - notably some graph-walking applications - but they are few and far between.&lt;br /&gt;&lt;br /&gt;Many problems that appear to be so complex that you need an imperative language turn out, on examination, to be complex only BECAUSE you are using an imperative language.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;I agree that functional languages like XSLT are quite useful. But many of the underlying hardware architectures are von Neumann based and von Neumann machines work best with imperative programs (languages).&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;If we believed that we would all still be writing in Assembler, or at any rate using GOTO statements.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;Isn't application processing faster using an imperative language? Aren't imperative languages easier for programmers to use?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;... on both ease-of-use and performance I would go for XSLT or XQuery in preference to lower-level languages every time.&lt;br /&gt;&lt;br /&gt;If you're receiving lexical XML from a web service, the time taken to process it in XSLT or XQuery is usually less than the time taken to parse and validate it. I would take a lot of convincing that a data binding approach is likely to be faster, given the cost of marshalling and unmarshalling the data.&lt;br /&gt;&lt;br /&gt;And on ease of use, I've seen programmers struggling with regenerating all their Java classes when the schema changes and it's horrendous. (Worse, I've seen people refuse to change the schema because it has become too expensive to contemplate!) Having two different models of the same data, understanding how they relate, and organizing yourself to keep them in sync is simply complexity that you don't need.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;XQuery can be usable when you need to access a small subset of an XML document. However, when one needs to access most of the data, or, worse, access the same data many times, data binding will have speed/memory advantage.&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;Evidence please! I don't see any reason why it should.&lt;br /&gt;&lt;br /&gt;(There are still people who maintain that coding in assembler is faster than in C, or that coding in C is faster than in Java. All the evidence is that there are very few people with the skills in the lower-level language to beat the optimizers for the higher-level language. It can be done if you try hard enough, but not by the average programmer.)&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;For most web service applications the Java (or other programming language) representation is actually primary, and XML is just being used for interchange. So surely application processing should be done in an imperative language, right?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;I don't think it matters which is primary, the complexity comes from having two representations and keeping them aligned. But I would have thought the format used for data interchange is primary in the sense that it needs to be agreed with other parties, whereas the Java representation is under local control. (Unless of course you're running the same code at both ends, in which case I'm not sure why you're using XML at all.)&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;Suppose I have a Web page that contains a form that users fill in. When the submit button is pressed the form data is sent to a server. Don't we need something like Java to receive the data? Doesn't this break the "all-XML" approach you advocate?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;It doesn't really matter too much if you have a bit of Java glue to accept the input and fire off the [XSLT] transformation, so long as it doesn't try to manipulate the data. But why use Java for this? There are plenty of higher-level frameworks that will do the job - since you're using forms, Orbeon does the job nicely.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;Why is there such variance in data binding tools with respect to mapping XML Schema structures into data structures in an imperative language?&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;XSD is used for other things [in addition to validation], notably data binding. To a large extent data binding is outside the scope of the XSD specification itself (XSD doesn't tell you how its types map to Java or C++) and this probably explains why there is wide variation between products in this area.&lt;br /&gt;&lt;br /&gt;Question:&lt;br /&gt;&lt;br /&gt;I would be interested to hear about any non-trivial and practical application other than "XML in, XML out", format changing kind, that are written exclusively in XSLT/XQuery.&lt;br /&gt;&lt;br /&gt;Michael Kay:&lt;br /&gt;&lt;br /&gt;How about an application for managing the creation, processing, and review of capital spending proposals in a large international corporation. The proposals are entered by form-filling using XForms, and each proposal is an XML document in an XML database. The rules defining the approval process (based on the nature of the capital project) are defined in a business rules document, also XML, (for example "anything over $1m requires CEO approval") and the abstract roles defined in that document (such as "CEO", or "finance controller, Taiwan") are mapped to real people in another XML document generated by a transformation of an XML dump of the LDAP directory. There's&lt;br /&gt;also an XML document that defines the corporate reporting structure, or actually two structures one functional and one geographic. These rules are used to construct an approval schedule for the proposal, which is also stored in the XML database, and emails are sent to the relevant people at the relevant times, with clickable URLs that they can use to access the application and approve or deny requests, or ask for more information. There's a full query/reporting system built using the same technology: you define a query by form-filling using XForms, and this generates an XQuery to get the data from the database and an XSLT stylesheet to format the query results.&lt;br /&gt;&lt;br /&gt;I believe the only parts of this application which are not written in XSLT, XQuery, XForms, or the Orbeon XML pipeline language (a precursor to XProc) are one or two simple extension functions to do things like sending an email or translating Base64 data from the LDAP directory.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7268961900154751223?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7268961900154751223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7268961900154751223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7268961900154751223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7268961900154751223'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/12/michael-kay-on-application-processing.html' title='Michael Kay on application processing'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-8322980478650960238</id><published>2008-12-06T09:35:00.000+05:30</published><updated>2008-12-06T09:50:17.034+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Feasibility of "do all application coding in the XML languages"?</title><content type='html'>Roger L. Costello initiated an interesting discussion (on, 01-Dec-08) on xml-dev mailing list, about following concept:&lt;br /&gt;&lt;br /&gt;I am exploring the idea of "do all application coding in the XML languages."&lt;br /&gt;&lt;br /&gt;Here is a response from a colleague:&lt;br /&gt;&lt;br /&gt;"... in general XSLT is cool but limited. If your transform requires any "higher math" or advanced functionality or external code libraries (such as geometry coordinate system libraries), you almost always have to go back to a higher level language (such as Java) at some point."&lt;br /&gt;&lt;br /&gt;Does my colleague make a true or false statement?&lt;br /&gt;&lt;br /&gt;XML professionals on the list expressed interesting opinions about this. Following is the link to this threaded discussion, &lt;a href="http://lists.xml.org/archives/xml-dev/200812/msg00007.html"&gt;http://lists.xml.org/archives/xml-dev/200812/msg00007.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Just thought of sharing this with readers of this blog (if you got a chance to visit here).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-8322980478650960238?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/8322980478650960238/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=8322980478650960238' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8322980478650960238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/8322980478650960238'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/12/feasibility-of-do-all-application.html' title='Feasibility of &quot;do all application coding in the XML languages&quot;?'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-4118834842054821732</id><published>2008-11-22T09:34:00.001+05:30</published><updated>2009-06-28T21:21:54.267+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xpath'/><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Are multiple XPath predicates same as boolean "and" operator</title><content type='html'>I had a doubt about this concept, and asked following question on &lt;a href="http://www.mulberrytech.com/xsl/xsl-list/"&gt;xsl-list&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Supposing I write the following XPath expressions,&lt;br /&gt;&lt;br /&gt;1) X[c1][c2]  or specifying generically, X[c1][c2][]...[cn]&lt;br /&gt;&lt;br /&gt;2) X[c1 and c2]  or specifying generically, X[c1 and c2 ... and cn]&lt;br /&gt;&lt;br /&gt;where c1, c2 etc. are boolean expressions.&lt;br /&gt;&lt;br /&gt;are the two forms (1 &amp; 2) above exactly equivalent (i.e., will they return the same nodeset/sequence)? I think yes ... but just wanted to confirm with the list.&lt;br /&gt;&lt;br /&gt;if 1 &amp; 2 are exactly equivalent, then what could be the rule of thumb for using which form in certain scenarios?&lt;br /&gt;&lt;br /&gt;There was a good discussion on the list about this, and list members shared some useful thoughts.&lt;br /&gt;&lt;br /&gt;Below is a summary of the points we discussed on the list.&lt;br /&gt;&lt;br /&gt;1. David Carlisle&lt;br /&gt;&lt;br /&gt;&gt; are the two forms (1 &amp; 2) above exactly equivalent&lt;br /&gt;&lt;br /&gt;No&lt;br /&gt;&lt;br /&gt;compare&lt;br /&gt;&lt;br /&gt;X[position()=2][position()=2]&lt;br /&gt;&lt;br /&gt;and&lt;br /&gt;&lt;br /&gt;[position()=2 and position()=2]&lt;br /&gt;&lt;br /&gt;the first one is&lt;br /&gt;&lt;br /&gt;()&lt;br /&gt;&lt;br /&gt;the second is&lt;br /&gt;&lt;br /&gt;X[2]&lt;br /&gt;&lt;br /&gt;David further wrote,&lt;br /&gt;&lt;br /&gt;context position (position()) and size (last()) do change. so basically repeated filters are equivalent to and unless any of them depend on position() or last(), including the special case of [integer] being equivalent to [position()=integer]&lt;br /&gt;this last case is what makes it tricky to do a static rewrite of this.&lt;br /&gt;&lt;br /&gt;If you have&lt;br /&gt;&lt;br /&gt;X[... foo ..][... bar ...]&lt;br /&gt;&lt;br /&gt;you can only rewrite that to&lt;br /&gt;&lt;br /&gt;X[(... foo ..) and (... bar ...)]&lt;br /&gt;&lt;br /&gt;if you know that neither expression will evaluate to a number at run time. &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;2. Vasu Chakkera&lt;br /&gt;&lt;br /&gt;If that were true, then the condition&lt;br /&gt;&lt;br /&gt;myelement[@myattribute][1] should be same as&lt;br /&gt;myelement[1][@myattribute], which is not true...&lt;br /&gt;&lt;br /&gt;The predicate order is important&lt;br /&gt;&lt;br /&gt;in a typical "and"&lt;br /&gt;&lt;br /&gt;[a and b] = [b and a]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;3. Andrew Welch&lt;br /&gt;&lt;br /&gt;Only / will change the context node, so I would've thought one predicate after the other is pretty much equivalent apart from cases that rely on size of the selection (which is the only thing that changes after each predicate).&lt;br /&gt;&lt;br /&gt;Mukul: I asked a related question in continuation to this.&lt;br /&gt;&lt;br /&gt;for real world XSLT/XPath programs, upto how many predicates can we typically see?&lt;br /&gt;&lt;br /&gt;I haven't seen programs using 3, 4 or more predicates.&lt;br /&gt;&lt;br /&gt;X[..][..][..][..]&lt;br /&gt;&lt;br /&gt;I have used only one or two predicates upto now.&lt;br /&gt;&lt;br /&gt;are excessively large number or predicates really useful? (though, the syntax allows that)&lt;br /&gt;&lt;br /&gt;I think perhaps, for complex 'and' conditions, using multiple predicates are useful.&lt;br /&gt;&lt;br /&gt;David shared an interesting observation about this:&lt;br /&gt;&lt;br /&gt;He has been using some stylesheets having upto 11 predicates.&lt;br /&gt;&lt;br /&gt;He wrote:&lt;br /&gt;&lt;br /&gt;&gt; are excessively large number or predicates really useful? (though, the syntax allows that)&lt;br /&gt;&lt;br /&gt;isn't that like asking if complicated expressions are useful? they are useful if you need them, otherwise they are not.&lt;br /&gt;&lt;br /&gt;3 or 4 predicates is totally routine but the most common reason for having larger numbers is to filter attributes&lt;br /&gt;&lt;br /&gt;[not(@purpose='iemode')]&lt;br /&gt;[not(@purpose='artifact')]&lt;br /&gt;[not(@purpose='w-dimension')]&lt;br /&gt;&lt;br /&gt;is equivalent to&lt;br /&gt;&lt;br /&gt;[not(@purpose='iemode') and&lt;br /&gt;[not(@purpose='artifact') and&lt;br /&gt;[not(@purpose='w-dimension')]&lt;br /&gt;&lt;br /&gt;but I'd almost always use the first form in XSLT 1.0 because it's easier to indent and easier to refactor, but if starting from the beginning in XSLT 2.0 I'd write it as&lt;br /&gt;&lt;br /&gt;[not(@purpose=('iemode','artifact','w-dimension'))]&lt;br /&gt;&lt;br /&gt;Mukul: This was a nice discussion I believe, and I have learnt few useful concepts.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-4118834842054821732?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/4118834842054821732/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=4118834842054821732' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4118834842054821732'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/4118834842054821732'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/11/are-multiple-predicates-same-as-boolean.html' title='Are multiple XPath predicates same as boolean &quot;and&quot; operator'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6882578850432149315</id><published>2008-11-04T11:52:00.000+05:30</published><updated>2008-12-01T21:45:16.160+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>fn:contains -&gt; multiple strings to compare with</title><content type='html'>An XSLT user asked following question on &lt;a href="http://www.mulberrytech.com/xsl/xsl-list/index.html"&gt;xsl-list&lt;/a&gt;:&lt;br /&gt;&lt;br /&gt;I want to have something that does this: contains('$d/ris:organ/text()', 'Hamburg' or 'Koblenz' or 'xxx'...) ===&gt; Compare 1 String with multpile strings.&lt;br /&gt;&lt;br /&gt;instead of: contains('$d/ris:organ/text()','Hamburg') or contains('$d/ris:organ/text()','Koblenz')...&lt;br /&gt;&lt;br /&gt;Andrew Welch suggested following answer:&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;some $x in ('Hamburg', 'Koblenz', 'xxx') satisfies&lt;br /&gt;contains($d/ris:organ/text(), $x)&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This uses the XPath 2.0 &lt;a href="http://www.w3.org/TR/xpath20/#id-quantified-expressions"&gt;quantified expression&lt;/a&gt;, "some".&lt;br /&gt;&lt;br /&gt;This is cool.&lt;br /&gt;&lt;br /&gt;I was prompted to share Andrew's answer here, because I thought of a lengthy and perhaps inefficient solution for this (I feel a bit stupid, actually :) ):&lt;br /&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                xmlns:xs="http://www.w3.org/2001/XMLSchema"&lt;br /&gt;                xmlns:my="http://my-functions"&lt;br /&gt;                version="2.0"&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;xsl:output indent="yes" omit-xml-declaration="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;xsl:template match="/"&amp;gt;&lt;br /&gt;  &amp;lt;xsl:variable name="str" select="'hello xxx dd'" /&amp;gt;&lt;br /&gt;  &amp;lt;xsl:variable name="list" select="('Hamburg','Koblenz','xxx')" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;xsl:if test="my:contains($str, $list)"&amp;gt;&lt;br /&gt;     matches&lt;br /&gt;  &amp;lt;/xsl:if&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;!-- a custom 'contains' implementation --&amp;gt;&lt;br /&gt; &amp;lt;xsl:function name="my:contains" as="xs:boolean"&amp;gt;&lt;br /&gt;  &amp;lt;xsl:param name="str" as="xs:string" /&amp;gt;&lt;br /&gt;  &amp;lt;xsl:param name="list" as="xs:string+" /&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;xsl:variable name="temp" as="xs:boolean*"&amp;gt;&lt;br /&gt;    &amp;lt;xsl:for-each select="$list"&amp;gt;&lt;br /&gt;      &amp;lt;xsl:if test="contains($str, .)"&amp;gt;&lt;br /&gt;        &amp;lt;xsl:sequence select="xs:boolean('true')" /&amp;gt;&lt;br /&gt;      &amp;lt;/xsl:if&amp;gt;&lt;br /&gt;    &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;  &amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;xsl:sequence select="if ($temp[1] = xs:boolean('true')) then&lt;br /&gt;xs:boolean('true') else xs:boolean('false')" /&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;/xsl:function&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6882578850432149315?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6882578850432149315/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6882578850432149315' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6882578850432149315'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6882578850432149315'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/11/fncontains-multiple-strings-to-compare.html' title='fn:contains -&gt; multiple strings to compare with'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6450671964418643790</id><published>2008-09-27T16:58:00.000+05:30</published><updated>2008-12-01T21:45:26.731+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>boolean value of a RTF, in XSLT 1.0</title><content type='html'>A recent discussion on &lt;a href="http://www.mulberrytech.com/xsl/xsl-list/"&gt;xsl-list&lt;/a&gt; taught me something about a feature of XSLT 1.0 language.&lt;br /&gt;&lt;br /&gt;Let's say there is a variable reference like following, in a XSLT 1.0 code:&lt;br /&gt;&lt;pre&gt;&amp;lt;xsl:variable name="temp"&amp;gt;&lt;br /&gt;  &amp;lt;!-- anything could be here --&amp;gt;&lt;br /&gt;&amp;lt;/xsl:variable&amp;gt;&lt;/pre&gt;According to the XSLT 1.0 specification, the contents of the variable temp is called a RTF (Result Tree Fragment). Now what will be the result of the following function call, boolean($temp)&lt;br /&gt;&lt;br /&gt;This will always return boolean value &lt;span style="font-style:italic;"&gt;true&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;Because, as defined in XSLT 1.0 specification,&lt;br /&gt;The boolean value of a node set, with at least one node, is &lt;span style="font-style:italic;"&gt;true&lt;/span&gt;. The RTF always has a &lt;span style="font-style:italic;"&gt;root&lt;/span&gt; node.&lt;br /&gt;&lt;br /&gt;It seems to me, that the function call, boolean($rtfVariable) is not very useful to applications, as it's always &lt;span style="font-style:italic;"&gt;true&lt;/span&gt;.&lt;br /&gt;&lt;br /&gt;This post applies to XSLT 1.0. I haven't cross checked what are the rules for this in XSLT 2.0.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6450671964418643790?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6450671964418643790/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6450671964418643790' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6450671964418643790'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6450671964418643790'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/09/boolean-value-of-rtf-in-xslt-10.html' title='boolean value of a RTF, in XSLT 1.0'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7084951017653927195</id><published>2008-09-12T19:44:00.000+05:30</published><updated>2009-01-19T20:43:59.909+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml'/><title type='text'>Should we include &lt;?xml version="1.0" ... in XPath data model, or DOM?</title><content type='html'>We all know that the following declaration statement appears at the beginning of most of the XML documents.&lt;br /&gt;&lt;br /&gt;[1]&lt;br /&gt;&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;&lt;br /&gt;&lt;br /&gt;But the details of the above statement is not included in a DOM tree, and neither it is part of the XPath (2.0) data model. To my opinion, this statement is used by the XML parser to initialize certain behaviors (or to enable certain properties).&lt;br /&gt;&lt;br /&gt;I just had a weird thought, that should we not include this information as part of XPath data model, perhaps as properties of the document node; and in case of DOM, part of the DOM tree? If this declaration is not present in the XML document, then the relevant properties can be empty sequences.&lt;br /&gt;&lt;br /&gt;The XML declaration is available in the XML infoset [2], but it's not included in a DOM, or the XPath data model.&lt;br /&gt;&lt;br /&gt;I think, perhaps the XML declaration information is not useful to end user applications, and is only useful to the XML parser.&lt;br /&gt;&lt;br /&gt;[2] &lt;a href="http://www.w3.org/TR/xml-infoset/"&gt;http://www.w3.org/TR/xml-infoset/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Michael Glavassevich on xml-dev list corrected me, about DOM:&lt;br /&gt;&lt;br /&gt;Information from the XML declaration is already stored in the DOM [3][4][5] (since DOM Level 3). Within the API the values have an effect on serialization, in-memory well-formedness checking and in-memory validation.&lt;br /&gt;&lt;br /&gt;[3] &lt;a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-version"&gt;http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-version&lt;/a&gt;&lt;br /&gt;[4] &lt;a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-encoding"&gt;http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-encoding&lt;/a&gt;&lt;br /&gt;[5] &lt;a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-standalone"&gt;http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#Document3-standalone&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7084951017653927195?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7084951017653927195/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7084951017653927195' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7084951017653927195'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7084951017653927195'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/09/should-we-include-version10-in-xpath.html' title='Should we include &amp;lt;?xml version=&quot;1.0&quot; ... in XPath data model, or DOM?'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-708374587530269458</id><published>2008-08-30T20:24:00.001+05:30</published><updated>2010-03-07T09:45:11.904+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Schema aware processing with XSLT 1.0</title><content type='html'>I wrote following &lt;a href="http://gandhimukul.tripod.com/xslt/sa-xslt-10.htm"&gt;article&lt;/a&gt;, about implementing some of the Schema aware stylesheet ideas (as defined in the XSLT 2.0 spec.) using a XSLT 1.0 processor and Java extensions, and a suitable validating XML parser. &lt;a href="http://mukulgandhi.blogspot.com/2008/05/output-validation-with-xslt-20.html"&gt;A requirement from a XSLT user&lt;/a&gt; on this blog motivated me to work on this idea.&lt;br /&gt;&lt;br /&gt;The article on my web site showcases just how few of the XSLT 2.0 Schema aware facilities like, validating the output tree (or even a result tree fragment) prior to serialization can be done. This covers one of the very important aspects of Schema aware XSLT 2.0 stylesheet design.&lt;br /&gt;&lt;br /&gt;I think it's not possible to implement following Schema aware XSLT 2.0 facilities, using XSLT 1.0 and extensions alone:&lt;br /&gt;&lt;br /&gt;1) Pass the validated XML instance tree to the XSLT processor, and the stylesheet is able to access Schema annotated XPath 2.0 data model tree. The XSLT 2.0 and XPath 2.0 languages define various Schema related instructions and expressions (for e.g., element(*, typeName) etc.), which cannot be simulated with XSLT 1.0 and extensions.&lt;br /&gt;&lt;br /&gt;2) Since we cannot access Schema annotated XPath 2.0 data model tree in a XSLT 1.0 stylesheet, we cannot access XML Schema type names in a stylesheet, which prohibits the enhanced static typing features in XSLT stylesheets.&lt;br /&gt;&lt;br /&gt;Using a complete Schema aware XSLT 2.0 system allows very rich static typing in XSLT stylesheets out of the box.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-708374587530269458?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/708374587530269458/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=708374587530269458' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/708374587530269458'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/708374587530269458'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/08/schema-aware-processing-with-xslt-10.html' title='Schema aware processing with XSLT 1.0'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-7748668447654443502</id><published>2008-08-22T18:43:00.000+05:30</published><updated>2008-12-01T21:45:47.905+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Nice use case for xsl:analyze-string instruction</title><content type='html'>I thought that this was interesting to share.&lt;br /&gt;&lt;br /&gt;Recently an XSLT user discussed a problem on xsl-list, which was solved by Jeni Tennison using XSLT 1.0 long time ago.&lt;br /&gt;&lt;br /&gt;I presented a XSLT 2.0 solution for the same problem. The 2.0 solution is lot shorter as compared to the 1.0 solution, and utilizes the XSLT 2.0 instruction, xsl:analyze-string.&lt;br /&gt;&lt;br /&gt;The link to this thread is at, &lt;a href="http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200808/msg00383.html"&gt;http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200808/msg00383.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This problem could be a nice use case for xsl:analyze-string instruction.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-7748668447654443502?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/7748668447654443502/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=7748668447654443502' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7748668447654443502'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/7748668447654443502'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/08/nice-use-case-for-xslanalyze-string.html' title='Nice use case for xsl:analyze-string instruction'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-5644727606853809743</id><published>2008-08-14T22:30:00.000+05:30</published><updated>2008-12-01T21:47:15.804+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Transforming tree structure from one format into another</title><content type='html'>An interesting question was asked on xsl-list,&lt;br /&gt;&lt;br /&gt;The input XML file is something as:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;Objs&amp;gt;&lt;br /&gt;   &amp;lt;obj name="a" child="b"/&amp;gt;&lt;br /&gt;   &amp;lt;obj name="b" child="c"/&amp;gt;&lt;br /&gt;   &amp;lt;obj name="b" child="d"/&amp;gt;&lt;br /&gt;   &amp;lt;obj name="c" child="e"/&amp;gt;&lt;br /&gt;&amp;lt;/Objs&amp;gt;&lt;/pre&gt;&lt;br /&gt;Let's say that XML file has only one root node.&lt;br /&gt;&lt;br /&gt;The output XML file would be:&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;Obj name="a"&amp;gt;&lt;br /&gt;  &amp;lt;Obj name="b"&amp;gt;&lt;br /&gt;      &amp;lt;Obj name="c"&amp;gt;&lt;br /&gt;         &amp;lt;Obj name="e"/&amp;gt;&lt;br /&gt;      &amp;lt;/Obj&amp;gt;&lt;br /&gt;      &amp;lt;Obj name="d"/&amp;gt;&lt;br /&gt;  &amp;lt;/Obj&amp;gt;&lt;br /&gt;&amp;lt;/Obj&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A tree structure is defined in input XML, by the 'name' and 'child' attributes. The output represents a true logical tree. We should be able to cater to unlimited number of tree nodes.&lt;br /&gt;&lt;br /&gt;We need to write a XSLT stylesheet for this.&lt;br /&gt;&lt;br /&gt;At first thought, I imagined that this could be a tough problem. But a little bit of patience helped me to write the stylesheet for this. The solution is presented below.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                version="1.0"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:template match="Objs"&amp;gt;&lt;br /&gt;  &amp;lt;xsl:variable name="start" select="obj[not(@name = ../obj/@child)]" /&amp;gt;&lt;br /&gt;  &amp;lt;xsl:variable name="startName" select="$start[1]/@name" /&amp;gt;&lt;br /&gt;  &amp;lt;Obj name="{$startName}"&amp;gt;&lt;br /&gt;    &amp;lt;xsl:for-each select="obj[(@name = $startName) and not(../obj/@name = @child)]"&amp;gt;&lt;br /&gt;      &amp;lt;Obj name="{@child}" /&amp;gt;&lt;br /&gt;    &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;    &amp;lt;xsl:call-template name="makeTree"&amp;gt;&lt;br /&gt;      &amp;lt;xsl:with-param name="list" select="obj[@name = $start/@child]" /&amp;gt;&lt;br /&gt;    &amp;lt;/xsl:call-template&amp;gt;&lt;br /&gt;  &amp;lt;/Obj&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:template name="makeTree"&amp;gt;&lt;br /&gt; &amp;lt;xsl:param name="list" /&amp;gt;&lt;br /&gt;&lt;br /&gt; &amp;lt;Obj name="{$list[1]/@name}"&amp;gt;&lt;br /&gt;   &amp;lt;xsl:for-each select="$list"&amp;gt;&lt;br /&gt;     &amp;lt;xsl:variable name="child" select="@child" /&amp;gt;&lt;br /&gt;     &amp;lt;xsl:choose&amp;gt;&lt;br /&gt;       &amp;lt;xsl:when test="not(../obj[@name = $child])"&amp;gt;&lt;br /&gt;         &amp;lt;Obj name="{$child}" /&amp;gt;&lt;br /&gt;       &amp;lt;/xsl:when&amp;gt;&lt;br /&gt;       &amp;lt;xsl:otherwise&amp;gt;&lt;br /&gt;         &amp;lt;xsl:call-template name="makeTree"&amp;gt;&lt;br /&gt;           &amp;lt;xsl:with-param name="list" select="../obj[@name = $child]" /&amp;gt;&lt;br /&gt;         &amp;lt;/xsl:call-template&amp;gt;&lt;br /&gt;       &amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;     &amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;   &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt; &amp;lt;/Obj&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;/pre&gt;&lt;br /&gt;At first thought, I felt that XSLT 2.0 constructs will be required to solve this problem. But the problem can be solved completely with a XSLT 1.0 stylesheet.&lt;br /&gt;&lt;br /&gt;My belief that XSLT is a wonderful language for processing XML data, became stronger after solving this problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-5644727606853809743?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/5644727606853809743/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=5644727606853809743' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5644727606853809743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/5644727606853809743'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/08/xslt-transforming-tree-structure-from.html' title='Transforming tree structure from one format into another'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6308515201888629928</id><published>2008-08-03T20:15:00.000+05:30</published><updated>2009-03-21T22:55:17.197+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>Multiple values for XSLT keys</title><content type='html'>An XSLT user, asked following question, on &lt;a href="http://www.mulberrytech.com/xsl/xsl-list/"&gt;xsl-list&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;How do I use multiple key values?&lt;br /&gt;&lt;br /&gt;Declaration:&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:key name="keyname" match="subroot" use="ccc"/&amp;gt;&lt;br /&gt;&lt;br /&gt;During the usage, I want to specify multiple values:&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="keyname" select="key('keyname', '11' or '22')"/&amp;gt; ==&gt;  Here I want to use multiple values 11 and 22.&lt;br /&gt;&lt;br /&gt;xsl-list members suggested useful options,&lt;br /&gt;&lt;br /&gt;1. David Carlisle&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="keyname" select="key('keyname', '22')|key('keyname', '11')"/&amp;gt;&lt;br /&gt;&lt;br /&gt;2. Michael Kay&lt;br /&gt;&lt;br /&gt;In XSLT 2.0, you can supply a sequence:&lt;br /&gt;&lt;br /&gt;key('keyname', ('111', '222'))&lt;br /&gt;&lt;br /&gt;In 1.0, you can supply a node-set with one value per node - but of course it's hard to set that up, you need the xx:node-set() function.&lt;br /&gt;&lt;br /&gt;I worked upon Mike's idea for a XSLT 1.0 solution,&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                   xmlns:exslt="http://exslt.org/common"&lt;br /&gt;                   exclude-result-prefixes="exslt"&lt;br /&gt;                   version="1.0"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:key name="x" match="subroot" use="ccc"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="x-values"&amp;gt;&lt;br /&gt; &amp;lt;v&amp;gt;11&amp;lt;/v&amp;gt;&lt;br /&gt; &amp;lt;v&amp;gt;22&amp;lt;/v&amp;gt;&lt;br /&gt;&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:template match="/root"&amp;gt;&lt;br /&gt; &amp;lt;result&amp;gt;&lt;br /&gt;   &amp;lt;xsl:for-each select="key('x', exslt:node-set($x-values)/v)"&amp;gt;&lt;br /&gt;     &amp;lt;value&amp;gt;&lt;br /&gt;       &amp;lt;xsl:value-of select="eee" /&amp;gt;&lt;br /&gt;     &amp;lt;/value&amp;gt;&lt;br /&gt;   &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt; &amp;lt;/result&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;&lt;br /&gt;Mukul: I think, this could be better than David's suggestion, because if we want to have quite large number of different values to search by the key, we just have to change following code fragment,&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="x-values"&amp;gt;&lt;br /&gt; &amp;lt;v&amp;gt;11&amp;lt;/v&amp;gt;&lt;br /&gt; &amp;lt;v&amp;gt;22&amp;lt;/v&amp;gt;&lt;br /&gt; &amp;lt;!-- more values --&amp;gt;&lt;br /&gt;&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;&lt;br /&gt;G. Ken Holman responded to my post, and provided a brilliant idea,&lt;br /&gt;&lt;br /&gt;The node-set extension can be avoided to achieve what you want.&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:for-each select="key('x', exslt:node-set($x-values)/v)"&amp;gt;&lt;br /&gt;&lt;br /&gt;The above can be replaced with standard XSLT 1.0 to read the stylesheet file as a source node tree.&lt;br /&gt;&lt;br /&gt;   &amp;lt;xsl:for-each&lt;br /&gt;     select="key('x',document('')/*/xsl:variable[@name='x-values']/v)"&amp;gt;&lt;br /&gt;&lt;br /&gt;Ken further wrote,&lt;br /&gt;&lt;br /&gt;I grant, though, that if your stylesheet is large then putting this into a small included or imported fragment would keep any overhead of building the tree small.&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;                   version="1.0"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:output method="xml" indent="yes" /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:key name="x" match="subroot" use="ccc"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:include href="ken2values.xsl"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:template match="/root"&amp;gt;&lt;br /&gt; &amp;lt;result&amp;gt;&lt;br /&gt;   &amp;lt;xsl:for-each select="key('x',$x-values)"&amp;gt;&lt;br /&gt;     &amp;lt;value&amp;gt;&lt;br /&gt;       &amp;lt;xsl:value-of select="eee" /&amp;gt;&lt;br /&gt;     &amp;lt;/value&amp;gt;&lt;br /&gt;   &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt; &amp;lt;/result&amp;gt;&lt;br /&gt;&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;ken2values.xsl&lt;/em&gt;&lt;br /&gt;&amp;lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&lt;br /&gt;               version="1.0"&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="x-values-data"&amp;gt;&lt;br /&gt; &amp;lt;v&amp;gt;11&amp;lt;/v&amp;gt;&lt;br /&gt; &amp;lt;v&amp;gt;22&amp;lt;/v&amp;gt;&lt;br /&gt;&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:variable name="x-values"&lt;br /&gt;             select="document('')/*/xsl:variable[@name='x-values-data']/v"/&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;&lt;br /&gt;I think, Ken's idea of having an included stylesheet (ken2values.xsl, above) is brilliant, as it is memory efficient, and we are able to avoid the node-set extension (as mentioned earlier).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-6308515201888629928?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/6308515201888629928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=6308515201888629928' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6308515201888629928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/6308515201888629928'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/08/xslt-multiple-values-for-key.html' title='Multiple values for XSLT keys'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-1604974206356564978</id><published>2008-07-27T22:43:00.005+05:30</published><updated>2010-03-07T09:45:11.905+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xerces'/><category scheme='http://www.blogger.com/atom/ns#' term='xml-schema'/><title type='text'>XML Schema 1.1 assertions implementation in Xerces-J</title><content type='html'>One of the interesting enhancements, that are happening recently to Xerces code base, is XML Schema 1.1 implementation.&lt;br /&gt;&lt;br /&gt;The &lt;a href="http://xerces.apache.org/xerces2-j/"&gt;Xerces-J&lt;/a&gt; team motivated me to implement some of the XML Schema 1.1 features into Xerces. I've started with the implementation of XML Schema 1.1 facility, "assertions".&lt;br /&gt;&lt;br /&gt;I've completed quite a bit of work regarding this, and am hoping that the assertions support I'm writing would be available in Xerces-J in near future.&lt;br /&gt;&lt;br /&gt;2008-11-04: Xerces team approved my work so far for assertions implementation, and have committed my patch to the Xerces code base. In the coming weeks, I would be working on integrating XPath 2.0 processing for assertions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5048327124946889578-1604974206356564978?l=mukulgandhi.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mukulgandhi.blogspot.com/feeds/1604974206356564978/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5048327124946889578&amp;postID=1604974206356564978' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1604974206356564978'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5048327124946889578/posts/default/1604974206356564978'/><link rel='alternate' type='text/html' href='http://mukulgandhi.blogspot.com/2008/07/assertions.html' title='XML Schema 1.1 assertions implementation in Xerces-J'/><author><name>Mukul Gandhi</name><uri>http://www.blogger.com/profile/18274168324155284011</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5048327124946889578.post-6313096765254268769</id><published>2008-07-26T11:25:00.000+05:30</published><updated>2008-12-01T21:46:17.940+05:30</updated><category scheme='http://www.blogger.com/atom/ns#' term='xslt'/><title type='text'>An elegant XSLT solution</title><content type='html'>We usually see some nice posts, on the xsl-list.&lt;br /&gt;&lt;br /&gt;David Carlisle recently posted a very elegant XSLT solution to a question asked on xsl-list. It's archived here, &lt;a href="http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200807/msg00574.html"&gt;http://www.biglist.com/lists/lists.mulberrytech.com/xsl-list/archives/200807/msg00574.html&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I really liked the following expression, in David's solution:&lt;br /&gt;&lt;br /&gt;&amp;lt;xsl:attribute name="level"&amp;gt;&lt;br /&gt;  &amp;lt;xsl:value-of select="sum(.|preceding::sect[1]/@depth)"/&amp;gt;&lt;br /&gt;&amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;&lt;br /&gt;I might have solved this problem differently, but not as elegantly like this. Nice thought, David!&lt;div class="b
