Package org.apache.ws.commons.schema.docpath

Building an XML Document's Conforming Path

See: Description

Package org.apache.ws.commons.schema.docpath Description

Building an XML Document's Conforming Path

This package is dedicated to walking an XML Document using the SAX API, and building a path through its XmlSchemaCollection to determine how the document conforms to its schema.

This is done in four steps:

  1. Build a state machine of the XmlSchemaCollection, represented as XmlSchemaStateMachineNodes.
  2. Start a SAX-based walk over the XML Document, either via SAXParser, when working with raw XML, or SaxWalkerOverDom when working with an Document.
  3. Use XmlSchemaPathFinder to build a series of XmlSchemaDocumentNodes and XmlSchemaPathNodes representing a valid walk through the XmlSchemaCollection.
  4. Add any application-specific information to the paths through the document using XmlSchemaDocumentNode.setUserDefinedContent(Object) and XmlSchemaPathNode.setUserDefinedContent(Object).

XmlSchemaStateMachineNode

XmlSchemaStateMachineNode represents a single node in the XmlSchema - either an element or a group - and the possible nodes that may follow (children of the element or group). Only one state machine node will be created by the XmlSchemaStateMachineGenerator for each XmlSchemaElement, meaning the XmlSchemaStateMachineNodes may loop back on themselves if an XML element is a child of itself.

XmlSchemaDocumentNode

As XmlSchemaStateMachineNodes represent the XML Schema, XmlSchemaDocumentNodes represent the XML Schema as applied to an XML Document. Each node represents all occurrences of the node in the XML Document, and a different set of children can be requested, one for each occurrence. Document nodes never loop back on themselves; if an element is a child of itself, a new document node instance will be created at each level in the tree.

As a result, the XmlSchemaDocumentNodes form a tree structure, starting with the root node of the document and working downward. User-defined content can be attached to each node in the tree using the XmlSchemaPathNode.setUserDefinedContent(Object). method.

XmlSchemaPathNode

Where XmlSchemaDocumentNodes represent the XML Schema structure used to describe the XML Document, XmlSchemaPathNodes define the actual walk through the XML Schema taken to represent that document.

Paths may go in four XmlSchemaPathNode.Directions:

XmlSchemaPathFinder

XmlSchemaPathFinder builds XmlSchemaDocumentNodes and XmlSchemaPathNodes from XmlSchemaStateMachineNode during a SAX walk of an XML document. In addition to confirming the XML Document conforms to its schema's structure, it will also confirm attribute and element content conform to its expected type.

Note: This is done entirely over a SAX walk, meaning the source need not be an XML Document at all. Any data structure that can be traversed via a SAX walk can be confirmed to conform against an expected XML Schema.

SaxWalkerOverDom

This allows SAX-based walks over Document objects. One can use this in conjunction with XmlSchemaPathFinder to confirm a document parsed using a DocumentBuilder conforms to its XML Schema.

DomBuilderFromSax

In the reverse direction, one can use DomBuilderFromSax to build an Document based on an XML Schema and a SAX walk over content that represents a document conforming to that XmlSchema . For best results, use XmlSchemaStateMachineGenerator to build a mapping of QNames to XmlSchemaStateMachineNodes. This is used by the DomBuilderFromSax to resolve ambiguities in how to generate the XML Document based on the schema.

Copyright © 2004–2017 The Apache Software Foundation. All rights reserved.