Click here to monitor SSC
Av rating:
Total votes: 93
Total comments: 6


Hima Bindu Vejella
Book Review: The Art of XSD - SQL Server XML schemas
10 June 2010

The 14 chapters of "The Art of XSD”, written by MVP Jacob Sebastian, will take the reader step-by–step all the way from the basics of XML Schema design to advanced topics on SQL Server XML Schema Collections. Reviewer Hima Bindu Vejella gives it an 8/10 rating, and gives us an excellent distilled description of what the book has to offer.

XSD Book Cover

Are you interested in developing XML Web Services as an integral part of your enterprise applications? Are you thinking of publishing your website or company news in the form of XML feeds? Are you planning to develop an application that consumes XML web services from third party providers such as Google, Amazon or Energy star? If you’re about to embark on any of these projects, then The Art of XSD will be an indispensable resource to you. The goal of the book is simple; to teach you everything you need to know to design and create an XML schema, which is naturally an essential component of any XML-based service.With this in hand, SQL Server developers with no prior knowledge of XSD can build powerful XML Schema Collections to create XSDs for Web Applications and Web services. Of course, if you’re new to using XML, the obvious first question is:

Why Use an XML Schema?

An XML Schema is itself an XML document, but what makes it special is that it describes or validates another XML document, defining the latter’s structure. If you’re wondering why you should use XML at all, it’s because XML has grown and matured over the past decade into a potentially powerful method for exchanging data, to the extent that Intel actually designed hardware with the primary intent of pushing the language’s adoption. More to the point, XML schemas support various datatypes, help in the understanding of secure data communications, are highly extensible, and are particularly well-suited to data representation.

By using an XSD (XML Schema Documents) to define the nature and structure of data which is to be shared between any number of services, it is possible to create dynamic, data-driven web applications for situations where information is changing rapidly. In addition, strong typing, standardized null representation, and XML-based language support make XSD more powerful than DTD (Document Type Definition, which is the alternative & older method of document structure definition). XSD becomes significantly more important when frequently-updated data needs to be exchanged in XML format with other internet-based applications, or when your application needs to consume published data sources such as weather-reports, stock exchange movements or currency conversion date, all of which are updated very frequently, sometimes several times a second. This is partly because the Schema (and an understanding of Schema) will make both incoming and outgoing feeds easy to interpret, and partly because you will be able to define and know (respectively) how rapidly the data feeds are changing. XSD plays a vital role in data exchange, describing information about data types, as well as the rules and the constraints that are being used to validate the values of elements and attributes.

What the Book Covers

Author Jacob Sebastian assumes no prior knowledge of XML on the part of the reader, and writes in simple English, using intuitive step-by-step examples. Jacob strives to explain the Art of XSD from its most basic principles so as to ensure his readers know everything they need to at every step. While the images and screenshots were not always legible (and admittedly it is a challenge to squeeze screenshots from modern monitors into compact books), his exhaustive and methodical approach makes the book thorough yet accessible, and well suited to an XSD beginner. After reading the book, you will have an excellent understanding of what XML and XSD are and why they’re relevant, as well as all the ins and outs of XML Schema components and designs. The importance of XML in real-time live applications is made clear throughout the book, and with Jacob’s guidance you’ll be an XSD artist in no time.

XML Schema Design

The book starts with the basics, covering “When do we need an XML Schema”, “Why do we need XSD?” and “How to write a document to define the basic structure of an XML document?” quickly and clearly. The XML Schema languages such as DTD and XDR are explained to some extent, and comparisons between them and XML are clearly made. Next up, to make sure you’re prepared to start writing XML Schemas immediately, Jacob describeds XML Schema support in SQL Server 2000, 2005 and 2008. For the record, that includes support for XML, OpenXML, SQLXML, Querying Data over HTTP, XML Views ,For XML, XML Data Type, XQuery Support and Lax Validation Support. The Schema Validation enhancements in SQL Server 2008 are explained in detail, keeping the book relevant and useful to current readers.

When it comes to actually writing an XML Schema, Namespaces are as essential as aliases are in T-SQL, and are clearly necessary when you need to avoid ambiguity and differentiate between similarly named classes. While there is a distinction between Default Namespaces and XSD Namespaces (which Jacob illuminates), it suffices to say for now that they give the document structure and add contextual meaning to the elements of the schema. Once you’ve wrapped you head around that, you need to start adding elements to your schema; and after you’ve structured and populated your schemas, the next step will be to use a SQL Server XML Schema Collection to store the definition of your documents so that you can perform Validations on them. That sounds simple enough, yet it turns out that SQL Server does not allow for easy alteration of Schema Collections, so dropping and recreating collections is recommended if you need to make any adjustments. Given how essential Schema Collections are throughout the rest of the book, Jacob takes care to provide a very clear explanation on how to use the SQL Server Management Studio XML/XSD editor for designing XML Schema quickly and painlessly. With the essential steps XML Schema creation covered, it’s time to test your knowledge.

At this point, and then again throughout the book, Jacob presents practical exercises relating to the fictional “North Pole Corporation”, walking you through how to build XSD schemas for a ‘real world’ Order Processing Application using the techniques covered in the book. Whilst these ‘labs’ sessions are invaluable, the book would have benefited from having each chapter finish with a more targeted exercise to cement the reader’s understanding of the concepts just covered. This would have been an elegant supplement to Jacob’s concise summaries at the end of each chapter.

XML Schema Components

Getting to grips with the components of XML Schemas is, at a primitive level, about understanding that the basic building blocks of a schema are elements and attributes, which need to be declared, and can be grouped or structurally controlled with Occurrence and Order Indicators. Elements & Attributes are the essential pillars for the construction of XML Schemas, and so it is good to see that Global & Local Element Declarations, the 14 Element Declaration Parameters , as well as mandatory & optional attributes are thoroughly explained. They can also be associated with certain XML Data-types, which allows for effective validation of your XML Schema documents. Jacob breaks down all of these definitions and permutations, explaining how they provide reusability and their role in defining XSD, as well as providing code samples to clearly demonstrate how these all fit together.

The question about whether information should be placed in an Element or an Attributes is one that keeps coming up. Occasionally there IS no question – only an element will do – and yet often there simply is no right answer, as they both perform much the same way. That being said, there are some restrictions on Attributes which may push you towards using Elements. Thankfully, entire chapters are dedicated to stepping through the internal structures of Element and Attribute Declarations, complete with descriptions of various parameters, and pointing out the difference between Global and Local Declarations (the former is, unsurprisingly, top-level; the latter is declared within the deeper structure of the document and has a more limited scope)

XML supports almost 50 built-in data-types, each of which has both a Value Space and Lexical Space characteristic. These data-types can be broken down into Primitive (i.e. base types of XML) or Derived (i.e. built on the backs of Primitive data-types), and are essential for efficient data description and validation. Jacob describes the properties of all 19 of XML's Primitive Data-types, as well as the 25 Derived Data Types, complete with demonstration snippets and enhancements to the data-types in SQL Server 2008. Given that, by this point, a lot of new ground has been covered, this chapter then finishes off with a case-study and guidelines, with the help of lab to cement understanding.

In addition to Attribute groups & Element groups, Order & Occurrence indicators, Local & Global Attribute declarations, the book also gives detailed breakdowns and explanations on Simple & Complex types. Simple Type Attributes (which can be derived from List, Union, Restriction actions) consist of Global (named) and Local (anonymous) content, whereas Complex Types are categorized as simple content, element only content, mixed content and empty content. Jacob focuses on deriving complex type from simple types, including examples and all the possible ways of doing it – crystal clear. Of course, if this all sounds like a bit of a confusing mess (and it can, when boiled down like this), then don’t worry; as you get deeper into the book, Jacob visualizes the relationships between components to make understanding easier. I found the explanations of the attributes and their usage in creating XSD to be detailed and useful, and this part of the book certainly serves as an excellent reference guide for learning about the various components of XSD.

XSD Validation

XML Schemas are fundamentally quite simple documents, so the key to making the most of them is in having a deep understanding of the various XML Schema components. As you may have gathered by now, Jacob makes sure that the book is able to provide that level of understanding. Now that you’ve been introduced to the menagerie of XML Schema components, you need to start thinking about validating the format your Schemas. Although XSD validation is touched upon at several points, it’s only now that you have a complete understanding (or at any rate, complete reference) of XSD that you’re in a position to really dig deeply into the topic. The pattern restrictions used to validate values in XML uses Regular Expression (Regex) patterns to do so. Anyone who is familiar with Regex patterns will feel comfortable with this aspect of XSD, particularly bearing in mind that Jacob has provided a comprehensive breakdown of the Regex meta characters which you’ll need to be specifically aware of in XSD. Given that this is broaching new territory (as far as the book is concerned), Jacob wisely finishes these explanations off with one of his “Lab Sessions”.

Advanced Topics

By this point, you should be comfortable enough with the fundamentals of effective schema design to be interested in some of the more advanced aspects the practice. For starters, while a schema declaration only needs a namespace attribute, there are a host of other attributes (such as targetNamespace and attributeFormDefault) which are useful because they control the behavior of the schema processor when it validates XML instances against the Schema collection (Just to clarify the terminology, a schema processor is just a software tool with validates an XML document against an XSD document). True to form, Jacob provides an excellent breakdown of these various attributes and clearly explains their effects and rules you should bear in mind when using them.

At the end of the book, Jacob dedicates a chapter to talking about SQL Server Schema Collections, why they are used and how to alter the Schemas they hold (which, unsurprisingly, consists of more than just designing XSD). Given that Schema collections are referenced through the book, this information might have been better placed earlier in the book, but the brief coverage in Chapter 2 is generally enough to see you through to this point. Ultimately, Jacob’s goal was probably to ensure the reader knew enough about XSDs to be able to use SQL Server Schema Collections effectively. Essentially, Schema Collections are just system objects, much like tables or indexes, designed to store XML schemas. Naturally, given that this is the interface between two different technologies, there are workarounds and frustrations (such as the fact that SQL Server will not preserve the value of your ID attributes), and Jacob does sterling work to cover as much of this territory as possible and offer expert advice.

Jacob has created a dedicated group on his website to accompany his book, and answer any questions his readers have about XML and XSD. You can find it on BeyondRelational.com.

Final words

Each chapter in the book takes you another step closer to creating your own XML Schemas, starting with the fundamentals and working through all the critical aspects of the XSD, and ultimately providing you with a solid grasp of the basics and some snippets of more advanced material. Prior knowledge of XSD is not required to read this book, as you will learn by following comprehensive examples at every stage of your journey. The book unfortunately does not cover Extending XML Schemas or XML Schema 1.1, and it would have been particularly helpful if the author had highlighted XML Schema best practices. Nevertheless, starting from the absolute basics, ‘The Art of XSD’ explains both what an XML Schema is and how to write one, ensuring you have the essential knowledge of the building blocks of XSD, and now how to declare and work with them. By the time you’re finished reading, you’ll be an accomplished XSD user, comfortable with integrating XML and SQL Server, and ready to employ these schemas in your real-time applications.

The material is well written, and the author succeeds in contextualizing the reader’s learning process by using realistic scenarios. Each chapter will leave you ready to tackle the next, and there’s no doubt in my mind that this book will give you the extensive base you need in order to progress to next level of expertise in XSD. It’s a good book and an excellent reference which every web developer should keep in their arsenal.

To read an early chapter of Jacob's book, see his article on 'Introduction to XML Schema'.

If you'd like To add “The Art of XSD” to your reference arsenal, the paperback is available from Amazon and Amazon (UK). Alternatively, if you'd like download a PDF version of the book, or read more of the details about the book, please go here to see The Art of XSD on Simple-Talk.



This article has been viewed 5880 times.
Hima Bindu Vejella

Author profile: Hima Bindu Vejella

Hima Bindu Vejella has been a Microsoft MVP and member for the Community-Credit Hall of Fame since 2006, and is currently working as a Technical Lead in US based MNC at Hyderabad, where she makes excellent use of her vast experience in software development using Microsoft Technologies. She is also an active community leader, as well as an author for aspalliance, dotnetslackers, PCQuest and, recently, Simple-Talk. She is a speaker, Book-Reviewer, DotnetUserGroupHyderabad India Lead, a Moderator at syntaxhelp, a INETA APAC Volenteer, a regular columnist for MUNDO.NET, and a Technical Member at dotnetspider. She has presented more than 200 sessions at various colleges and events both virtual and 'real', covering topics ranging from MVP awareness to VS2010. Hima is passionate about giving back to the community, and she can be reached at himabvejella@gmail.com. Alternatively, you can follow her on Twitter (@himanet), or read her personal blog at HimaBinduVeljella.blogspot

Search for other articles by Hima Bindu Vejella

Rate this article:   Avg rating: from a total of 93 votes.


Poor

OK

Good

Great

Must read
 
Have Your Say
Do you have an opinion on this article? Then add your comment below:
You must be logged in to post to this forum

Click here to log in.


Subject: One of the BEST XML Book Around
Posted by: pinaldave (view profile)
Posted on: Friday, June 11, 2010 at 1:14 AM
Message: Hello,

I am not the XML guy but this is one of the best XML book I ever finished back to back.

I strongly recommended every one to start on the same.

BEST BOOK EVER for XML!

Kind Regards,
Pinal

Subject: This is an essential book. Nice review, Hima!
Posted by: Phil Factor (view profile)
Posted on: Friday, June 11, 2010 at 2:05 AM
Message: Jacob's book has always been undervalued. Either you have to become an XML expert yourself, or else you should have Jacob's book. There are other books about XSD, but this is the one for SQL Server DBAs. Thanks to Hima for doing justice to this excellent book.

Subject: Puzzled
Posted by: BuggyFunBunny (view profile)
Posted on: Friday, June 11, 2010 at 10:48 AM
Message: I remain puzzled. I simply don't understand why relational database developers would countenance xml storage, or anything to do with it, save any requirement for transfer (as Pascal and I, et al, have remarked, xml ain't so good at that either; I've had to deal with such and they're a mess).

If your personal physician became enthralled with leeching procedures, what would you think of him/her as a physician? That s/he had fallen under the spell of ancient incompetence? xml is IMS in sheep's clothing, created by folks (lawyers, specifically; well SGML which coders begat xml) who had no clue what data models were all about.

Subject: Fantastic article on the excellent book
Posted by: Venkatesan Prabu (not signed in)
Posted on: Sunday, June 13, 2010 at 6:21 PM
Message: Hima,

Amazed on seeing this article. Kudos on your great initiative.

Cheers,
Venkatesan Prabu .J
http://venkattechnicalblog.blogspot.com/

Subject: Excellent Review
Posted by: Vijay Raj (not signed in)
Posted on: Wednesday, June 16, 2010 at 10:16 AM
Message: Excellent Review Hima. A Must Read book. Good work from you. Happy to see your profile in simple-talk as an Indian Author. Keep your good work going.

Subject: Nice Review Hima
Posted by: Great work (not signed in)
Posted on: Thursday, June 17, 2010 at 12:38 PM
Message: Great work Hima from you to write this review.
Keep the good work going!

 










Phil Factor
Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL Server... Read more...



 View the blog
Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...

SQL Source Control: The Development Story
 Often, there is a huge difference between software being easy to use, and easy to develop. When your... Read more...

How to Import Data from HTML pages
 It turns out that there are plenty of ways to get data into SQL Server from websites, whether the data... Read more...

SQL Scripts Manager: An Appreciation
 SQL Scripts Manager is Simple-Talk's present to its readers. William Brewer was an enthusiastic... Read more...

Hosted Team Foundation Server 2010 Review
 Team Foundation Server (TFS) has expanded its remit to support the whole software development process,... Read more...

Beginning SQL Server 2005 Reporting Services Part 1
 Steve Joubert begins an in-depth tour of SQL Server 2005 Reporting Services with a step-by-step guide... Read more...

Ten Common Database Design Mistakes
 Database design and implementation is the cornerstone of any data centric project (read 99.9% of... Read more...

Reading and Writing Files in SQL Server using T-SQL
 SQL Server provides several "standard" techniques by which to read and write to files but, just... Read more...

Beginning SQL Server 2005 Reporting Services Part 2
 Continuing his in-depth tour of SQL Server 2005 Reporting Services, Steve Joubert demonstrates the most... Read more...

Creating CSV Files Using BCP and Stored Procedures
 Nigel Rivett demonstrates some core techniques for extracting SQL Server data into CSV files, focussing... Read more...

Over 400,000 Microsoft professionals subscribe to the Simple-Talk technical journal. Join today, it's fast, simple, free and secure.

Join Simple Talk