XML Schema « XML « Java Articles

Home
Java Articles
1.Build Deploy
2.Class
3.Core Library
4.Data Types
5.Database JDBC
6.Design
7.Development
8.File Input Output
9.Graphics Desktop
10.J2EE Enterprise
11.J2ME Wireless
12.JVM
13.Language
14.Library Product
15.Network
16.Security
17.SOA Web Services
18.Test
19.Web Development
20.XML
Java Articles » XML » XML Schema 
On the other hand, everyone (and their dog!) is looking to get into XML. Using the Extensible Markup Language seems to be even more popular than hacking the Linux kernel these days and will even make your boss happy. So how do those two fit together? Well, XML, and specifically XML Schema, provides a perfect means of detailing constraints for Java data. And with a simple Java-based framework, you can build those constraints into Java objects and compare application data against them. The end result is a flexible, robust, XML-based framework for all your Java validation needs.

With servlets and JSP pages sending all submitted parameters as textual values (an array of Java Strings, to be exact), your application must convert to a different data type at every step of user input. That converted data is most likely passed to session beans. The beans can ensure type safety (requiring an int, for example), but not the value range. So validation must occur again. Finally, business logic may need to be applied. (Does Doc Marten make this boot in a size 10?) Only then can computation safely be performed, and results supplied to the user. If you're starting to feel overwhelmed, good! You are starting to see the importance of validation, and why this series might be right for you.

In an effort to resolve that problem, at least until the powers that be come up with a robust API for validation, this series takes a detailed look at validation in Java. That isn't an explanation on using JavaScript in your HTML or expensive third-party libraries but instead on creating a simple validation framework based on existing standards. The focus is on ease of use and a simple means to add new validation rules into the data constraints without cluttering business and presentation logic with validation details.

XML has two main advantages: first, it offers a standard way of structuring data, and, second, we can specify the vocabulary the data uses. We can define the vocabulary (what elements and attributes an XML document can use) using either a document type definition (DTD) or the XML Schema language.

In Part 1, I talked at a conceptual level about problems common to applications with user input and raised the issue of validation. I discussed using Java properties files as well as hard-coded solutions and the various shortcomings of those approaches. Finally, I suggested that XML Schema might provide a means to represent data constraints easily and completely and previewed the framework that is the focus of this series. In Part 2, I demonstrated how you could use some simple Java classes to represent data constraints defined in an XML Schema. This laid the groundwork for building a set of these Constraint instances and then comparing Java data (Strings, ints, Dates, etc.) to these data constraints. In Part 3, I rounded out the framework, providing the SchemaParser class to parse the XML Schema and build up these constraints. And finally, I showed you the Validator class, which would take data and a constraint name and return whether or not the data was valid with regard to the supplied named constraint. For those of you who haven't read these parts, I strongly recommend that you read the first trilogy of articles before moving on.

In this article, the Xerces2-j and JAXP parsers are used to validate an XML document with an XML schema. In Xerces2-j, schema validation is integrated with the SAXParser and DOMParser parsers. In JAXP, DocumentBuilder classes are used to validate a XML document. XML schema validation is illustrated with an XML document comprising of a catalog. This article is structured into the following sections:

The IXRetail digital receipt XML schema works for all purchases from standard cash and credit card to more innovative shoppers making a payment via a cell phone or other hand held device, according to the Association for Retail Technology Standard (ARTS).

The detente only affects development efforts that embrace XML, but that covers an increasingly large swath of developers. IBM and Microsoft are far from alone in standard Web services; Oracle, Computer Associates, BEA and others have agreed to support this technology paradigm, which is spurred on in no small part by the efforts of the Web Services Interoperability (WS-I) Organization.

New support for the IBM's alphaWorks XML Schema Quality Checker directly within the Stylus Studio XML IDE enables developers to check their XML data models against various well-established best practices governing XML Schema style and quality. Developers can read a free online tutorial with step by step instructions on how build fabulous XML Schemas with Stylus Studio and IBM alphaWorks XML Schema Quality.

OSS Nokalva announced the availability of the OSS XML Schema (XSD) Tools for Java. The OSS XSD Tools are now available for C/C+, and Java. The OSS XSD Tools for Java bind XSD schema to Java representations.

XML Journal - XML Schema Doc Generator 1.0 Released The buldocs XML team has announced version 1.0 of xnsdoc, a tool to generate documentation of W3C XML Schema in a JavaDoc like visualisation. According to them, 'xnsdoc supports all common schema design practices like chameleon, russian doll, salami slice, venetian blind schemas or circular schema references.'

A given XML Schema defines a set of new names such as the names of elements, types, attributes, attribute groups, whose definitions and declarations are written in the schema. Listing 3 defines the names as InvoiceNo, ProductID, and ProductCode.

XML Schema provides validation capabilities that weren't available with Document Type Definitions. Xerces-Java 2.0 provides virtually complete support for the W3C's XML Schemas, and beyond. This tutorial guides you through the process of using schema validation with Xerces-Java 2.0.

Although there are a number of parsers and tools that use schemas to validate or analyze XML documents, tools that allow querying and advanced manipulation of schema documents themselves are still being built. The Schema Infoset Model (AKA the IBM Java Library for Schema Components, or just "the library") provides a rich API library that models schemas -- both their concrete representations (perhaps in a schema.xsd file) and the abstract concepts in a schema as defined by the specification. As anyone who has read the schema specs knows, they're quite detailed, and this model strives to expose all the details within any schema. This will then allow you to efficiently manage your schema collection, and empower higher level schema tools -- perhaps schema-aware parsers and transformers.

As you can see, even without support for multiple schemas, you can use XMLBeans for XML processing and still be able to manage schema variations. We hope you'll try this technique in your own work.

XML Schema was approved as a W3C Recommendation in May, 2001 and is now being widely used for structuring XML documents for e-commerce and Web Services applications.

w_ww.__j__av_a__2__s___._c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.