Just a quick heads up on the support for XML Schema Data Types. I've just
checked into CVS an alpha version of package org.dom4j.schema.* which
contains a SchemaDocumentFactory that will ultimately support XML Schema
Data Types.

Ultimately this means that

* as a document is constructed with the SchemaDocumentFactory all
simpleTypes (dateTime, int, long, positiveInteger et al) will be validated
and

* the Java data objects (java.util.Date, Number, Integer, Long et al) can be
extracted from the simpleType Element or Attribute instances using
getData().

So if you had access to an Attribute which was defined as an "int" in the
XML Schema then the following would work..

    Attribute ageAttribute = element.attribute( "age");
    Integer age = (Integer) ageAttribute.getData();

    // hey lets change it...
    ageAttribute.setData( new Integer( age.intValue() + 1 ) );

For those interested there is a JUnit test case at
src/test/org/dom4/schema/TestManualSchema.java which is currently working,
even if its only for the "int" / Integer data type ;-)


Right now only the standard simpleType Attributes are supported. Derived
simpleType attributes and simpleType Elements will follow shortly. All the
validatoin and DataType repository is provided by Sun's XML DataTypes
library

http://www.sun.com/software/xml/developers/xsdlib/

Also the SchemaDocumentFactory must be manually loaded with the XML Schema
document prior to loading instance documents. This is a useful feature in
general as it allows you to load a schema and use it to create documents
which don't have the xsi:namespaceSchemaLocation or
xsi:noNamespaceSchemaLocation attributes defined. (e.g. a normal XML
document without any DTD or XML Schema declarations, e.g. in SOAP /
XProtocol messages)

If you just want to use data types in your XML documents you can just create
an XML Schema document containng simpleTypes for elements and attributes,
load it into a SchemaDocumentFactory instance and away you go, the data
types can be used on any XML document, whether a DTD or XML Schema
declaration is present or not. The aforementioned JUnit test demonstates
this in action. Basically the magic happens in the following method on
SchemaDocumentFactory:-

    public void loadSchema( Document schemaDocument );

Ultimately, the SchemaDocumentFactory will totally support the auto loading
of XML Schema documents via the xsi:namespaceSchemaLocation or
xsi:noNamespaceSchemaLocation attributes, so valid XML Schema instance
documents will just work and be data type aware.

Note that the support of XML Schema Data Types is only meant to support Java
data types and partial validation. It might also be useful for building more
optimal object models too (based on the knowledge of attributes and content
models).

For full XML Schema Validation, particularly of complexType rules, I'd
recommend using an underlying SAX (or DOM) based parser such as Xerces 1.4
to do the validation, just use dom4j as a nice object model for working with
the document and Java data types.

James


_______________________________________________
dom4j-dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dom4j-dev

Reply via email to