Showing posts with label schema. Show all posts
Showing posts with label schema. Show all posts

Monday, September 1, 2008

GSoC 2008 ....... Done

You may have noticed that my blog has gone rather silent in the last couple of months. Well, the reason was my Google Summer of Code (GSoC) project. The final deadline was on 18th of August so I worked really hard to deliver the goods on time and finally I can proudly state that I managed to successfully complete my project on time.

The objective of my GSoC project was to implement XML schema type alternatives support for Apache Xerces2/J, the legendary open source XML parser for Java applications. Type alternatives is the answer from W3C XML schema working group, for conditional type assignment problem. This feature was first introduced in the XML schema 1.1 structures specification. Type alternatives allow a type to be assigned to an element dynamically at validation time based on one or more conditions. Conditions are expressed as XPath 2.0 expressions. Here is an example element declaration which uses XML schema type alternatives.

As stated in the above code snippet the declared type of the message element is the complex type called messageType. However the element declaration also contains a few type alternatives. These type alternatives allow the type of the message elements to be determined at the validation time. Based on the conditions stated as the test attribute values the schema validator will assign a type for the message element prior to validating its content. The expressions '@kind' and '@code' refer to two attributes of the message element. The first type alternative will assign the type called messageTypeString if the kind attribute has the value 'string' and the code attribute has a value greater than 1000.

When the schema validator encounters an element declaration with one or more type alternatives it will evaluate the test expressions one by one until an expression which evaluates to true is found. When such a matching type alternative is found the corresponding type will be assigned to the element. If none of the type alternatives match then a default type will be assigned.

My project mainly consisted of two main sections. First section of the project was to implement the type alternatives traversal support so that Xerces2/J can properly traverse an XML schema document which contains type alternatives and add the corresponding information to the schema grammar. Implementing this was fairly easy and I managed to complete it prior to th GSoC mid term evaluations. The second part of the project was to implement type alternatives validation. This was fairly difficult since I had to develop a bare minimal XPath 2.0 implementation for Xerces2/J. Developing the XPath processor actually covered a significant portion of the entire project.

My workings will be fully available in the Xerces2/J code base (even now the code related to traversal part is in one of the SVN branches) very soon. All in all it was a great learning experience as it was a great opportunity for me to learn a whole bunch of cool technologies like XML, XML schema, and XPath 2.0. I also got the opportunity to put some of my knowledge on theory of computing into action and sharpen my programming skills. I would like to give my heartiest gratitude to the Google, the Apache community and very specially to my mentor Khaled Noaman for being a very supportive guide right from the start of my project.

Tuesday, April 29, 2008

GSoC 2008 is On

The all important initial phase of the Google Summer of Code 2008 (GSoC) came to an end last week. The selected project proposals were published on the GsoC website on 21st April. I too applied for this year's contest and my project proposal to implement type alternatives for Apache Xerces2-J was among the qualified proposals. The Apache Software Foundation has received around 30 slots this year and one of them is allocated to my proposal (yipeee!!!). I consider this as an great opportunity to learn and master XML and XML schema while contributing to a world renowned open source project.

Apache Xerces2-J is a high performance, standard compliant XML parser. It currently supports a number of XML related standards like XML 1.0, XML 1.1, DOM, SAX, JAXP and XML schema 1.0. A variety of open source and proprietary software projects make use of Apache Xerces2-J as the core XML parsing and processing mechanism. The reason for this immense popularity of Apache Xerces2-J is probably the high number of standards it supports and the way it supports them. Nowadays Apache Xerces2-J is even distributed along with popular Sun's JDK.

Xerces development team is currently involved in getting Xerces2-J to support the XML schema 1.1 standard which is the latest XML schema specification. XML schema 1.1 specification like its predecessor is comprised of three main parts namely the primer, structures and data types. Type alternatives is a feature that falls under the XML schema 1.1: structures spec. This is one of the most significant additions to the XML schema standard and it provides a well organized mechanism to implement conditional type assignment which has been in the XML schema feature wish lists for years.

With type alternatives XML elements can be assigned types based on one or more conditions (thus the name conditional type assignment). The conditions are specified as Xpath 2.0 expressions and the relationship between a condition and the corresponding type can be expressed using the 'alternative' element as in the following example.

The Xpath expression which specifies the condition is expressed as the value of the 'test' attribute and the corresponding type is expressed as the value of the 'type' attribute. Alternatively one could use 'simpleType' or 'complexType' child elements to specify the type instead of using the 'type' attribute. A complete example illustrating XML schema type alternatives would be as follows.
Here we have defined an element named 'value' which is of declared type 'valueType'. But based on the actual value of the 'kind' attribute the 'value' elements can have a different governing type. When XML schema validations are performed the elements will be validated against their governing types.

Type alternatives can add lot more flexibility to the way XML schema documents are used and it gives more freedom and power to the XML schema author. With type alternatives the XML elements having the same name can be of different governing types. In the above example different 'value' elements can take one of three types (integer, short or byte). Also the same element can have a governing type that is different of the declared type. This wouldn't have been possible if not for the type alternatives.

All in all type alternatives is a very interesting and useful feature for XML schema authors. That makes it very important for Xerces2-J to support it. I have worked with XML and XML parsers like DOM and SAX a lot in the past. I have used Apache Xerces2-J in a number of occasions too. But to be honest I haven't really worked with XML schema much. So this really is a big learning opportunity to me. I have been studying the XML schema specs for the last few weeks and I have already collected a whole bunch of stuff on XML schema to my knowledge base.

My heart is itching to start with the coding part but I know that there are lot of things to be studied, analyzed and clarified before I get to that point. Wish me luck!!