Skip Headers

Oracle® XML Reference 10g (9.0.4) Part Number B10926-01 |
Home | Contents | Index

# 5
XML Schema Processing

The full functionality of XML Schema Processor for Java is contained in the `oracle.XML.parser.schema` package.

This chapter discusses the following topics:

- XMLSchema Class

- XMLSchemaNode

- XSDAttribute Class

- XSDBuilder Class

- XSDComplexType Class

- XSDConstrainingFacet Class

- XSDDataValue Class

- XSDElement Class

- XSDException

- XSDGroup Class

- XSDIdentity Class

- XSDNode Class

- XSDSimpleType Class

- XSDConstantValues Interface

- XSDValidator Class

  See Also: Oracle Application Developer's Guide - XML

## XMLSchema Class

This class contains a set of Schema for different target namespaces. They are used by XSDParser for instance XML documents validation and by XSDBuilder as imported schemas.

#### Syntax

    public class XMLSchemaNode extends oracle.xml.parser.schema.XSDNode

##### Table 5-1 Summary of Methods of XML Schema

Constructor | Description
--- | ---
XMLSchema() | XMLSchema constructor.
getAllTargetNS() | Returns all the Target Name space defined in the schema.
getSchemaByTargetNS() | Returns schemaNode for the given namespace.
getSchemaTargetNS() | Returns the top level schema's target Namespace.
getXMLSchemaNodeTable() | Returns XMLSchemaNode table.
getXMLSchemaURLS() | Returns XMLSchema URLs.
printSchema() | Print schema information.

## XMLSchema()

XMLSchema constructor. Throws XSDException. The options are described in the following table.

Syntax | Description
--- | ---
    public XMLSchema()
| Default constructor.
    public XMLSchema(int n);
| Constructs schema given initial size of schemanode set.

Parameter | Description
--- | ---
    n
| Initial size of schemanode set

## getAllTargetNS()

Returns all the Target Name space defined in the schema.

#### Syntax

    public java.lang.String[] getAllTargetNS();

## getSchemaByTargetNS()

Returns schemaNode for the given namespace.

#### Syntax

    public XMLSchemaNode getSchemaByTargetNS( String namespace);

Parameter | Description
--- | ---
    namespace
| Target namespace of the required schema.

## getSchemaTargetNS()

Returns the top level schema's target Namespace. In case there are more than one top level schema, the last one being built is returned.

#### Syntax

    public String getSchemaTargetNS();

## getXMLSchemaNodeTable()

Returns XMLSchemaNode table as a hashtable.

#### Syntax

    public java.util.Hashtable getXMLSchemaNodeTable();

## getXMLSchemaURLS()

Returns XMLSchema URLs as an array.

#### Syntax

    public java.lang.String[] getXMLSchemaURLS();

## printSchema()

Print schema information. The options are described in the following table.

Syntax | Description
--- | ---
    public void printSchema();
| Prints schema information.
    public void printSchema(
         boolean all);
| Prints schema information, including build-ins.

Parameter | Description
--- | ---
    all
| Flag to indicate that all information, including build-ins, should be printed

## XMLSchemaNode

This class contains sets of top level Schema components in a target namespace.

#### Syntax

    public class XMLSchemaNode extends oracle.xml.parser.schema.XSDNode

##### Table 5-2 Summary of Methods of XMLSchemaNode

Method | Description
--- | ---
XMLSchemaNode() | XMLSchema constructor.
getAttributeDeclarations() | Returns all the top level attributes in the schema.
getComplexTypeSet() | Returns all the top level complex type elements in the schema.
getComplexTypeTable() | Returns the complex type definitions.
getElementSet() | Returns all the top level elements in the schema.
getSimpleTypeSet() | Returns all the top level simpleType elements in the schema.
getSimpleTypeTable() | Returns the simple type definitions.
getTargetNS() | Returns targetNS of the schema.
getTypeDefinitionTable() | Returns the type definitions.

## XMLSchemaNode()

`XMLSchema` constructor.

#### Syntax

    public  XMLSchemaNode();

## getAttributeDeclarations()

Returns all the top level attributes in the schema as an array.

#### Syntax

    public XSDAttribute getAttributeDeclarations();

## getComplexTypeSet()

Returns all the top level complex type elements in the schema as an array.

#### Syntax

    public XSDNode getComplexTypeSet();

## getComplexTypeTable()

Returns the complex type definitions as a hashtable.

#### Syntax

    public java.util.Hashtable getComplexTypeTable();

## getElementSet()

Returns all the top level elements in the schema as an array.

#### Syntax

    public XSDNode getElementSet();

## getSimpleTypeSet()

Returns all the top level simpleType elements in the schema as an array.

#### Syntax

    public XSDNode getSimpleTypeSet();

## getSimpleTypeTable()

Returns the simple type definitions, in a hashtable.

#### Syntax

    public java.util.Hashtable getSimpleTypeTable();

## getTargetNS()

Returns`targetNS` of the schema. Overrides `XSDNode.getTargetNS()`.

#### Syntax

    public String getTargetNS();

## getTypeDefinitionTable()

Returns the type definitions as a hashtable.

#### Syntax

    public java.util.Hashtable getTypeDefinitionTable();

## XSDAttribute Class

This class represents Schema Attribute declaration.

#### Syntax

    public class XSDAttribute extends oracle.xml.parser.schema.XSDNode

##### Table 5-3 Summary of Methods of XSDAttribute

Method | Description
--- | ---
getDefaultVal() | Returns the value of 'default' attributes for element, and the value of 'value' attributes based on 'use' attribute.
getFixedVal() | Returns the value of 'fixed' attribute for of element, and the value of 'value' attribute based on 'use' attribute.
getName() | Returns the name of the node.
getRefLocalname() | Returns he local name of the resolved 'ref' attribute.
getRefNamespace() | Returns the namespace of the resolved 'ref' attribute.
getRefState() | Returns refState.
getTargetNS() | Returns target namespace.
getType() | Returns the node type.
isRequired() | Checks if the attribute is required.

## getDefaultVal()

Returns the value of 'default' attr in case of element, and the value of 'value' attr based on 'use' attribute.

#### Syntax

    public String getDefaultVal();

## getFixedVal()

Returns the default value of 'fixed' attr in case of element, and the value of 'value' attr based on 'use' attribute.

#### Syntax

    public java.lang.String getFixedVal();

## getName()

Returns the name of the node. Overrides `XSDNode.getName()` in class `XSDNode.`

#### Syntax

    public String getName();

## getRefLocalname()

Returns the refLocal name of the resolved 'ref' attribute

#### Syntax

    public String getRefLocalname();

## getRefNamespace()

Returns the RefNamespace of the resolved 'ref' attribute.

#### Syntax

    public String getRefNamespace();

## getRefState()

Returns refState value. The return value is one of the following: `TYPE_UNRESOLVED`, `TYPE_RESOLVED`, `REF_UNRESOLVED`, `REF_RESOLVED.`

#### Syntax

    public int getRefState();

## getTargetNS()

Returns target namespace. `XSDNode.getTargetNS()` in class `XSDNode.`

#### Syntax

    public String getTargetNS();

## getType()

Returns the node type which is either simpleTypeor complexType.

#### Syntax

    public XSDNode getType();

## isRequired()

Checks if the attribute is required.

#### Syntax

    public boolean isRequired();

## XSDBuilder Class

Builds an XMLSchema object from XMLSchema document. XMLSchema object is a set of objects (Infoset items) corresponding to top-level schema declarations & definitions. Schema document is 'XML' parsed and converted to a DOM tree. This schema DOM tree is 'Schema' parsed in a following order: (if any) builds a schema object and makes it visible. (if any) is replaced by corresponding DOM tree. Top-level declarations & definitions are registered as a current schema infoset items. Finally, top-level tree elements (infoset items) are 'Schema' parsed. The result XMLSchema object is a set (infoset) of objects (top-level input elements). Object's contents is a tree with nodes corresponding to low-level element/group decls/refs preceded by node/object of type SNode containing cardinality information (min/maxOccurs).

#### Syntax

    public class XSDBuilder

##### Table 5-4 Summary of Methods of XSDBuilder

Method | Description
--- | ---
XSDBuilder() | Class constructor.
build() | Builds an XMLSchema object or document.
getObject() | Returns XML schema object.
setEntityResolver() | Sets an EntityResolver for resolving imports/include.
setError() | Sets XMLError object.
setLocale() | Sets locale for error reporting.

## XSDBuilder()

XSDBuilder constructor.

#### Syntax

    public XSDBuilder() throws XSDException;

## build()

Build and returns an XMLSchema object/document. An Exception is thrown if Builder fails to build an XMLSchema object. The options are described in the following table.

Syntax | Description
--- | ---
    public Object build(
         InputStream in,
         URL baseurl);
| Builds an XMLSchema object from an input stream and a URL.
    public Object build(
         Reader r,
         URL baseurl);
| Builds an XMLSchema object from a reader and a URL.
    public Object build(
         String sysId);
| Builds an XMLSchema object from system id.
    public Object build(
         String ns,
         String sysid);
| Builds an XMLSchema object from a namespace and system id.
    public Object build(
         String ns,
         URL sysid);
| Builds an XMLSchema object from a namespace and URL.
    public Object build(
         URL schemaurl);
| Builds an XMLSchema object from a URL.
    public Object build(
         XMLDocument schemaDoc);
| Builds XMLSchema from XML document.
    public Object build(
         XMLDocument[] schemaDocs,
         URL baseurl);
| Builds XMLSchema from an array of XML documents and a URL.
    public Object build(
         XMLDocument doc,
         String fragment,
         String ns,
         URL sysid);
| Build an XMLSchema object from XML document, a fragment, namespace, and system id.
    public Object build(
         XMLDocument schemaDoc,
         URL baseurl);
| Build XMLSchema from XML document and URL.

Parameter | Description
--- | ---
    baseurl
| URL used to resolve relative refs for any import/include in document
    doc
| XMLdocument contain the schema element
    fragment
| Fragment ID of the schema element
    in
| Inputstream of Schema
    ns
| Schema target namespace used to validate targetNamespace
    r
| Reader of Schema
    schemaDoc
| XMLDocument
    schemaDocs
| Array of XMLDocuments
    sysId
| Schema location
    url
| URL of Schema

## getObject()

Returns XML schema object.

#### Syntax

    public Object getObject();

## setEntityResolver()

Sets an EntityResolver for resolving imports/include. See also `org.xml.sax.EintityResolver.`

#### Syntax

    public void setEntityResolver( org.xml.sax.entityResolver entResolver);

Parameter | Description
--- | ---
    entResolver
| EntityResolver

## setError()

Sets XMLError object.

#### Syntax

public void setError( XMLError er);

Parameter | Description
--- | ---
    er
| XMLError object

## setLocale()

Sets locale for error reporting.

#### Syntax

    public void setLocale(L ocale locale);

Parameter | Description
--- | ---
    locale
| Locale object

## XSDComplexType Class

This class represents the Schema ComplexType definition.

#### Syntax

    public class XSDComplexType extends oracle.xml.parser.schema.XSDNode

##### Table 5-5 Summary of Methods of XSDComplexType

Method | Description
--- | ---
getAttributeDeclarations() | Returns attribute declarations of this complex type.
getAttributeWildcard() | Returns attribute wildcard of this complex type.
getBaseType() | Returns the base type of this complextype.
getContent() | Returns content of XSDComplexType.
getDerivationMethod() | Returns information on how was this type derived from its parent type.
getElementSet() | Returns an array of all the local elements inside a complexType element.
getGroup() | Returns the attribute group or the child & attribute group.
getRefLocalname() | Returns the local name of resolved 'base' attr.
getTypeGroup() | Returns type group of Complex Type.
init() | Initializes complex type.
isAbstract() | Returns TRUE if the Complex Type is abstract.

## getAttributeDeclarations()

Returns attribute declarations of this complex type; does not include wild card array of attribute declarations.

#### Syntax

    public XSDAttribute getAttributeDeclarations();

## getAttributeWildcard()

Returns attribute wildcard of this complex type.

#### Syntax

    public oracle.xml.parser.schema.XSDAny getAttributeWildcard();

#### Returns

The attribute wildcard if has one

## getBaseType()

Returns the base type of this complextype.

#### Syntax

    public XSDNode getBaseType();

## getContent()

Returns content of XSDComplexType.

#### Syntax

    public int getContent();

## getDerivationMethod()

Returns information on how was this type derived from its parent type. One of `EXTENSION_DERIVATION` or `RESTRICTION_DERIVATION`.

#### Syntax

    public short getDerivationMethod();

## getElementSet()

Returns an array of all the local elements inside a complexType element.

#### Syntax

    public XSDNode getElementSet();

## getGroup()

Returns the attribute group or the child & attribute group.

#### Syntax

    public XSDGroup getGroup();

## getRefLocalname()

Returns the local name of resolved 'base' attr.

#### Syntax

    public java.lang.String getRefLocalname();

## getTypeGroup()

Returns type group of Complex Type.

#### Syntax

    public XSDGroup getTypeGroup();

## init()

Initializes complex type.

#### Syntax

    public static void init();

## isAbstract()

Returns `TRUE` if the Complex Type is abstract.

#### Syntax

    public boolean isAbstract();

## XSDConstrainingFacet Class

This class represents Schema Constraining facet for Data Type.

#### Syntax

    public class XSDConstrainingFacet extends java.lang.Object implements
    oracle.xml.parser.schema.XSDTypeConstants

I

##### Table 5-6 Summary of Methods of XSDConstrainingFacet

Method | Description
--- | ---
getFacetId() | Returns the facet id.
getLexicalEnumeration() | Returns the LEXICAL enumeration of the constraining facet.
getLexicalValue() | Returns the LEXICAL value of the constraining facet.
getName() | Returns the name of the constraining facet.
isFixed() | Checks whether facet is fixed and cannot be changed.
setFixed() | Sets if the facet is fixed and cannot be changed.
validateFacet() | Validates the value against the constraint facet.

## getFacetId()

Returns the facet id.

#### Syntax

    public int getFacetId();

## getLexicalEnumeration()

Returns the `LEXICAL` enumeration of the constraining facet.

#### Syntax

    public java.util.Vector getLexicalEnumeration();

## getLexicalValue()

Returns the `LEXICAL` value of a constraining facet.

#### Syntax

    public String getLexicalValue();

## getName()

Returns the name of the constraining facet.

#### Syntax

    public String getName();

## isFixed()

Checks whether facet is fixed and cannot be changed. Returns `TRUE` for fixed, `FALSE` otherwise.

#### Syntax

    public boolean isFixed();

## setFixed()

Sets whether facet is fixed and cannot be changed. `TRUE` for fixed, `FALSE` otherwise.

#### Syntax

    public void setFixed( boolean fixed);

Parameter | Description
--- | ---
    value
| Value being validated.

## validateFacet()

Validates the value against the constraint facet.

#### Syntax

    public void validateFacet( XSDDataValue value);

Parameter | Description
--- | ---
    value
| Value being validated.

## XSDDataValue Class

This class represents data values for Schema Simple Type.

#### Syntax

    public class XSDDataValue extends java.lang.Object implements
    oracle.xml.parser.schema.XSDTypeConstants

##### Table 5-7 Summary of Methods of XSDDataValue

Method | Description
--- | ---
compareTo() | Compares two values returns -1 for smaller, 0 for equal, and 1 for greater.
getLength() | Returns the length of `STRING/BINARY` value.
getLexicalValue() | Returns `LEXICAL` value from the `XSDDataValue` class.
getPrecision() | Returns the precision of decimal value.
getScale() | Returns the scale of decimal value.

## compareTo()

Compares two values; returns -1 for smaller, 0 for equal, and 1 for greater. Throws `XSDException` if the data values are not comparable.

#### Syntax

    public int compareTo( XSDDataValue val);

## getLength()

Gets the length of `STRING/BINARY` value. Throws `XSDException` if the data value is neither of these types.

#### Syntax

    public int getLength();

## getLexicalValue()

Returns `LEXICAL` value from the `XSDDataValue` class.

#### Syntax

    public String getLexicalValue();

## getPrecision()

Returns the precision of decimal value. Throws `XSDException` if the data values are not decimal type.

#### Syntax

    public int getPrecision();

## getScale()

Returns the int value of a decimal scale. Throws `XSDException` if the data value is not decimal type.

#### Syntax

    public int getScale();

## XSDElement Class

The `XSDElement` class represents the Schema element declaration.

#### Syntax

    public class XSDElement

##### Table 5-8 Summary of Methods of XSDElement

Method | Description
--- | ---
findEquivClass() | Finds the equivalent class corresponding to this class.
getDefaultVal() | Returns the value of 'default' attr in case of element, and the value of 'value' attr based on 'use' attribute.
getEquivClassRef() | Returns the local name of the resolved equivalent class.
getFixedVal() | Returns the value of 'fixed' attr in case of element, and the value of 'value' attr based on 'use' attribute.
getIdentities() | Returns the set of identities.
getMaxOccurs() | Returns the maxOccurs.
getMinOccurs() | Returns the minOccurs.
getName() | Returns Name.
getRefLocalname() | Returns the local name of the resolved 'ref' attribute.
getRefNamespace() | Returns the namespace of the resolved 'ref' attribute.
getRefState() | Returns refState.
getSubstitutionGroup() | Returns the substitutionGroup.
getTargetNS() | Sets target namespace.
getType() | Sets the node type.
isAbstract() | Returns TRUE if element abstract.
isNullable() | Returns TRUE if element nullable.
setMaxOccurs() | Sets the maxOccurs.
setMinOccurs() | Sets the minOccurs.

## findEquivClass()

Finds the equivalent class corresponding to this class.

#### Syntax

    public XSDElement findEquivClass( String ns,
                                      String nm);

Parameter | Description
--- | ---
    ns
| Namespace.
    rm
| Name.

## getDefaultVal()

Returns the value of 'default' attr in case of element, and the value of 'value' attr based on 'use' attribute.

#### Syntax

    public String getDefaultVal();

## getEquivClassRef()

Returns the local name of the resolved equivalent class.

#### Syntax

    public String getEquivClassRef();

## getFixedVal()

Returns the value of 'fixed' attr in case of element, and the value of 'value' attr based on 'use' attribute

#### Syntax

    public java.lang.String getFixedVal();

## getIdentities()

Returns the set of identities, as an array.

#### Syntax

    public XSDIdentity getIdentities();

## getMaxOccurs()

Returns the maxOccurs

#### Syntax

    public int getMaxOccurs();

## getMinOccurs()

Returns the minOccurs.

#### Syntax

    public int getMinOccurs();

## getName()

Returns the name of the node.

#### Syntax

    public String getName();

## getRefLocalname()

Returns the local name of the resolved 'ref' attribute

#### Syntax

    public String getRefLocalname();

## getRefNamespace()

Returns the namespace of the resolved 'ref' attribute

#### Syntax

    public String getRefNamespace();

## getRefState()

Returns refState. The return value is one of the following: `TYPE_UNRESOLVED`, `TYPE_RESOLVED`, `REF_UNRESOLVED`, `REF_RESOLVED`.

#### Syntax

    public int getRefState();

## getSubstitutionGroup()

Returns the substitutionGroup

#### Syntax

    public java.util.Vector getSubstitutionGroup();

## getTargetNS()

Returns target namespace.

#### Syntax

    public java.lang.String getTargetNS();

## getType()

Returns the node type, either simpleType or complexType.

#### Syntax

    public XSDNode getType();

## isAbstract()

Returns `TRUE` if this element is abstract.

#### Syntax

    public boolean isAbstract();

## isNullable()

Returns `TRUE` if this element is nullable.

#### Syntax

    public boolean isNullable();

## setMaxOccurs()

Sets the maxOccurs.

#### Syntax

    public void setMaxOccurs( int max);

Parameter | Description
--- | ---
    maxOccurs
| value

## setMinOccurs()

Sets the minOccurs.

#### Syntax

    public void setMinOccurs( int min);

Parameter | Description
--- | ---
    minOccurs
| value

## XSDException

Indicates that an exception occurred during XMLSchema validation.

#### Syntax

    public class XSDException extends Exception

## getMessage()

Overrides getMessage() in class Throwable in order to construct error message from error id and error parameters. The options are described in the following table.

Syntax | Description
--- | ---
    public String getMessage()
| Constructs error message from error id and error parameters
    public String getMessage(
         XMLError err)
| Constructs localized error message based on the XMLError sent as parameter

Parameter | Description
--- | ---
    err
| XMLError class used to get the error message

## XSDGroup Class

`The XSDGroup` class represents the Schema group definition.

#### Syntax

    public class XSDGroup

##### Table 5-9 Summary of Methods of XSDIdentity

Method | Description
--- | ---
getMaxOccurs() | Returns the maxOccurs.
getMinOccurs() | Returns the minOccurs.
getNodeVector() | Returns the particles of the group stored in nodeVector.
getOrder() | Returns the composite type - `ALL`, `SEQUENCE`, `CHOICE`.
setMaxOccurs() | Sets maxOccurs.
setMinOccurs() | Sets minOccurs.

## getMaxOccurs()

Returns the maxOccurs.

#### Syntax

    public int getMaxOccurs();

## getMinOccurs()

Returns the minOccurs.

#### Syntax

    public int getMinOccurs();

## getNodeVector()

Returns the particles of the group stored in nodeVector.

#### Syntax

    public java.util.Vector getNodeVector();

## getOrder()

Returns the composite type - `ALL`, `SEQUENCE`, or `CHOICE`

#### Syntax

    public int getOrder();

## setMaxOccurs()

Sets maxOccurs.

#### Syntax

    public void setMaxOccurs( int max);

Parameter | Description
--- | ---
    maxOccurs
| value

## setMinOccurs()

Sets the minOccurs.

#### Syntax

    public void setMinOccurs( int min);

Parameter | Description
--- | ---
    minOccurs
| value

## XSDIdentity Class

Represents Schema Identity-Constraint definition: `Unique`, `Key`, and `Keyref`.

#### Syntax

    public class XSDIdentity extends oracle.xml.parser.schema.XSDNode

##### Table 5-10 Summary of Methods of XSDIdentity

Method | Description
--- | ---
getFields() | Returns the fields.
getNodeType() | Returns the node type.
getRefer() | Returns the reference key.
getSelector() | Returns the selector.

## getFields()

Returns the fields.

#### Syntax

    public java.lang.String[] getFields();

## getNodeType()

Returns the node Type. Overrides `XSDNode.getNodeType()` in class `XSDNode.`

#### Syntax

    public int getNodeType();

## getRefer()

Returns the referenced key

#### Syntax

    public String getRefer();

## getSelector()

Returns the selector.

#### Syntax

    public String getSelector();

## XSDNode Class

Root class for most of XSD classes. Contains fields and methods corresponding to XMLSchema definition attributes.

#### Syntax

    public class XSDNode

##### Table 5-11 Summary of Methods of XSDNode

Method | Description
--- | ---
getName() | Returns the name of the node.
getNamespaceURI() | Returns namespace uri for psv.
getNodeType() | Returns the type of XSDNode.
getTargetNS() | Returns target namespace.
isNodeType() | Checks if the node is of the give type.

## getName()

Returns the name of the node.

#### Syntax

    public java.lang.String getName();

## getNamespaceURI()

Returns namespace uri for psv.

#### Syntax

    public String getNamespaceURI()

## getNodeType()

Returns the type of XSDNode.

#### Syntax

    public int getNodeType();

## getTargetNS()

Returns target namespace.

#### Syntax

    public java.lang.String getTargetNS();

## isNodeType()

Checks if the node is of the give type.

#### Syntax

    public boolean isNodeType( int type);

Parameter | Description
--- | ---
    type
| Type of node that is being checked.

## XSDSimpleType Class

This class represents Schema Simple Type definition.

#### Syntax

    public class XSDSimpleType implements oracle.xml.parser.schema.XSDTypeConstants

##### Table 5-12 Summary of Methods of XSDSimpleType

Method | Description
--- | ---
XSDSimpleType() | Class constructor.
derivedFrom() | Derive a type from the given base type.
getBase() | Returns the base type of this type.
getBasicType() | Gets the basic type from which this type was derived.
getBuiltInDatatypes() | Gets a built-in datatype.
getFacets() | Get the facets.
getMaxOccurs() | Get the value of maxOccurs.
getMinOccurs() | Get the value of minOccurs.
getVariety() | Get the variety of the type.
isAbstract() | Returns TRUE if this Type is abstract.
setFacet() | Sets a facet for the datatype (Internal private API).
setMaxOccurs() | Sets the value of maxOccurs.
setMinOccurs() | Sets the value of minOccurs.
setSource() | Sets the base type of the datatype; for aggregate types sets the type of the component of the aggregate type.
validateValue() | Validates the string value with the facets defined for this type.

## XSDSimpleType()

Class constructor. The options are described in the following table.

Syntax | Description
--- | ---
    public XSDSimpleType();
| Default constructor.
    public XSDSimpleType(
         int basic,
         String tnm);
| Implements W3C XMLSchema Datatype definition.

Parameter | Description
--- | ---
    basic
| Id of the Primitive type from which this one is derived.
    tnm
| Name of this type.

## derivedFrom()

Derives a type from the given base type. Throws `XSDException` if new type cannot be created.

#### Syntax

    public static XSDSimpleType derivedFrom( XSDSimpleType source,
                                             String nm,
                                             String var);

Parameter | Description
--- | ---
    source
| XSDSimpleType The base type
    nm
| The name of the new type
    var
| The method of derivation

## getBase()

Retrieves the base type.

#### Syntax

    public XSDSimpleType getBase();

## getBasicType()

Retrieves the basic type from which this type was derived.

#### Syntax

    public int getBasicType();

## getBuiltInDatatypes()

Gets a built-in datatype. Throws `XSDException` if the type is not a valid name.

#### Syntax

    public static Hashtable getBuiltInDatatypes();

Parameter | Description
--- | ---
    type
| Name of the built-in type.

## getFacets()

Retrieves the facets.

#### Syntax

    public XSDConstrainingFacet getFacets();

## getMaxOccurs()

Retrieves value of maxOccurs.

#### Syntax

    public int getMaxOccurs();

## getMinOccurs()

Retrieves the value of minOccurs.

#### Syntax

    public int getMinOccurs();

## getVariety()

Retrieves the variety of the type.

#### Syntax

    public java.lang.String getVariety();

## isAbstract()

Returns `TRUE` if this type is abstract, `FALSE` otherwise.

#### Syntax

    public boolean isAbstract();

## setFacet()

Sets a facet for the datatype (Internal private API). Throws `XSDException` if the facet is invalid.

#### Syntax

    public void setFacet( String facetName,
                          String value);

Parameter | Description
--- | ---
    facetName
| Name of the facet being set.
    value
| Value of the facet.

## setMaxOccurs()

Set the value of maxOccurs

#### Syntax

    public void setMaxOccurs(int max);

Parameter | Description
--- | ---
    max
| Number of maximum occurrences.

## setMinOccurs()

Set the value of minOccurs.

#### Syntax

    public void setMinOccurs( int min);

Parameter | Description
--- | ---
    min
| Number of minimum occurrences.

## setSource()

Sets the base type of the datatype, or in case of aggregate types sets the type of the component of the aggregate type. Throws `SDException` if the src is not a valid type.

#### Syntax

    public void setSource( XSDNode src);

Parameter | Description
--- | ---
    src
| XSDNode source.

## validateValue()

Validates the string value with the facets defined for this type. Throws `XSDException` if the value is not valid.

#### Syntax

    public void validateValue( String val);

Parameter | Description
--- | ---
    val
| Value to be validated.

## XSDConstantValues Interface

This interface defines constants for the W3C Schema Processor.

#### Syntax

    public interface XSDTypeConstants

##### Table 5-13 Constants Defined in XSDConstantValues

Constant | Definition
--- | ---
    _abstract
    public static final String _abstract
    _all
    public static final String _all
    _annotation
    public static final String _annotation
    _any
    public static final String _any
    _anyAttribute
    public static final String _anyAttribute
    _anySimpleType
    public static final String _anySimpleType
    _anyType
    public static final String _anyType
    _attrFormDefault
    public static final String _attrFormDefault
    _attribute
    public static final String _attribute
    _attributeGroup
    public static final String _attributeGroup
    _attrTag
    public static final String _attrTag
    _base
    public static final String _base
    _block
    public static final String _block
    _blockDefault
    public static final String _blockDefault
    _choice
    public static final String _choice
    _complexContent
    public static final String _complexContent
    _complexType
    public static final String _complexType
    _content
    public static final String _content
    _default
    public static final String _default
    _derivedBy
    public static final String _derivedBy
    _element
    public static final String _element
    _elementOnly
    public static final String _elementOnly
    _elemFormDefault
    public static final String _elemFormDefault
    _empty
    public static final String _empty
    _enumeration
    public static final String _enumeration
    _equivClass
    public static final String _equivClass
    _extension
    public static final String _extension
    _false
    public static final String _false
    _field
    public static final String _field
    _final
    public static final String _final
    _finalDefault
    public static final String _finalDefault
    _fixed
    public static final String _fixed
    _form
    public static final String _form
    _group
    public static final String _group
    _id
    public static final String _id
    _import
    public static final String _import
    _include
    public static final String _include
    _itemType
    public static final String _itemType
    _key
    public static final String _key
    _keyref
    public static final String _keyref
    _lax
    public static final String _lax
    _list
    public static final String _list
    _maxOccurs
    public static final String _maxOccurs
    _memberTypes
    public static final String _memberTypes
    _minOccurs
    public static final String _minOccurs
    _mixed
    public static final String _mixed
    _nall
    public static final String _nall
    _name
    public static final String _name
    _namespace
    public static final String _namespace
    _nil
    public static final String _nil
    _nillable
    public static final String _nillable
    _nnany
    public static final String _nnany
    _nnlist
    public static final String _nnlist
    _nnlocal
    public static final String _nnlocal
    _nnother
    public static final String _nnother
    _nntargetNS
    public static final String _nntargetNS
    _noNSSchemaLocation
    public static final String _noNSSchemaLocation
    _notation
    public static final String _notation
    _null
    public static final String _null
    _nullable
    public static final String _nullable
    _optional
    public static final String _optional
    _pattern
    public static final String _pattern
    _processContents
    public static final String _processContents
    _prohibited
    public static final String _prohibited
    _publicid
    public static final String _publicid
    _qualified
    public static final String _qualified
    _redefine
    public static final String _redefine
    _ref
    public static final String _ref
    _refer
    public static final String _refer
    _required
    public static final String _required
    _restriction
    public static final String _restriction
    _restrictions
    public static final String _restrictions
    _schema
    public static final String _schema
    _schemaLocation
    public static final String _schemaLocation
    _selector
    public static final String _selector
    _sequence
    public static final String _sequence
    _simpleContent
    public static final String _simpleContent
    _simpleType
    public static final String _simpleType
    _skip
    public static final String _skip
    _strict
    public static final String _strict
    _substitution
    public static final String _substitution
    _systemid
    public static final String _systemid
    _targetNS
    public static final String _targetNS
    _textOnly
    public static final String _textOnly
    _this
    public static final String _this
    _true
    public static final String _true
    _type
    public static final String _type
    _undef
    public static final String _undef
    _union
    public static final String _union
    _unique
    public static final String _unique
    _unqualified
    public static final String _unqualified
    _use
    public static final String _use
    _value
    public static final String _value
    _version
    public static final String _version
    _xmlns
    public static final String _xmlns
    ABSENT_NS
    public static final int ABSENT_NS
    ACCEPTED
    public static final int ACCEPTED
    ALL
    public static final int ALL
    ANY
    public static final int ANY
    ANY_ATTRIBUTE
    public static final int ANY_ATTRIBUTE
    ANY_NODE
    public static final String ANY_NODE
    ATTRIBUTE
    public static final int ATTRIBUTE
    ATTRIBUTE_GROUP
    public static final int ATTRIBUTE_GROUP
    AUTO_VALIDATION
    public static final String AUTO_VALIDATION
    BASE_RESOLVED
    public static final int BASE_RESOLVED
    BASE_UNRESOLVED
    public static final int BASE_UNRESOLVED
    BASE_URL
    public static final String BASE_URL
    CHOICE
    public static final int CHOICE
    constName
    public static final String constName[]
    cyclicChain
    public static final int cyclicChain
    DATATYPE
    public static final int DATATYPE
    DONE
    public static final int DONE
    ELEMENT
    public static final int ELEMENT
    ELEMENT_CHILD
    public static final int ELEMENT_CHILD
    ELEMENT_ONLY
    public static final int ELEMENT_ONLY
    elemNotNullable
    public static final int elemNotNullable
    EMPTY
    public static final int EMPTY
    EQUIV_RESOLVED
    public static final int EQUIV_RESOLVED
    EQUIV_UNRESOLVED
    public static final int EQUIV_UNRESOLVED
    ERROR
    public static final int ERROR
    EXTENTION
    public static final int EXTENTION
    FACET_CHILD
    public static final int FACET_CHILD
    FAKE_NODE
    public static final XSDGroup FAKE_NODE
    FIXED_SCHEMA
    public static final String FIXED_SCHEMA
    GROUP
    public static final int GROUP
    IDENTITY_KEY
    public static final int IDENTITY_KEY
    IDENTITY_KEYREF
    public static final int IDENTITY_KEYREF
    IDENTITY_UNIQUE
    public static final int IDENTITY_UNIQUE
    IMPORT
    public static final int IMPORT
    INCLUDE
    public static final int INCLUDE
    INFINITY
    public static final int INFINITY
    invalidAttr
    public static final int invalidAttr
    invalidAttrVal
    public static final int invalidAttrVal
    invalidChars
    public static final int invalidChars
    invalidContent
    public static final int invalidContent
    invalidDerivation
    public static final int invalidDerivation
    invalidElem
    public static final int invalidElem
    invalidETag
    public static final int invalidETag
    invalidFacet
    public static final int invalidFacet
    invalidFixedChars
    public static final int invalidFixedChars
    invalidNameRef
    public static final int invalidNameRef
    invalidNS
    public static final int invalidNS
    invalidParsAttr
    public static final int invalidParsAttr
    invalidPrefix
    public static final int invalidPrefix
    invalidRef
    public static final int invalidRef
    invalidSTag
    public static final int invalidSTag
    invalidTargetNS
    public static final int invalidTargetNS
    LAX_VALIDATION
    public static final String LAX_VALIDATION
    missingAttr
    public static final int missingAttr
    MIXED
    public static final int MIXED
    needsSource
    public static final int needsSource
    NEW_STATE
    public static final int NEW_STATE
    NO_CHILD
    public static final int NO_CHILD
    noDefinition
    public static final int noDefinition
    NOT_DONE
    public static final int NOT_DONE
    NOTATION
    public static final int NOTATION
    notComplete
    public static final int notComplete
    notSubTypeOf
    public static final int notSubTypeOf
    NS_FRAME
    public static final int NS_FRAME
    NS_RESOLVER
    public static final String NS_RESOLVER
    REDEFINE
    public static final int REDEFINE
    REF_RESOLVED
    public static final int REF_RESOLVED
    REF_UNRESOLVED
    public static final int REF_UNRESOLVED
    refToAbstractElem
    public static final int refToAbstractElem
    refToAbstractType
    public static final int refToAbstractType
    RESTRICTION
    public static final int RESTRICTION
    SCHEMA_NS
    public static final int SCHEMA_NS
    SEQ
    public static final int SEQ
    STRICT_VALIDATION
    public static final String STRICT_VALIDATION
    TEXT_ONLY
    public static final int TEXT_ONLY
    TOP_LEVEL
    public static final int TOP_LEVEL
    TYPE
    public static final int TYPE
    TYPE_RESOLVED
    public static final int TYPE_RESOLVED
    TYPE_UNRESOLVED
    public static final int TYPE_UNRESOLVED
    UNDEF
    public static final int UNDEF
    undefinedType
    public static final int undefinedType
    unexpectedAttr
    public static final int unexpectedAttr
    unexpectedElem
    public static final int unexpectedElem
    unnamedAttrDecl
    public static final int unnamedAttrDecl
    VALIDATION_MODE
    public static final String VALIDATION_MODE
    XSDAUG2000NS
    public static final String XSDAUG2000NS
    XSDDATATYPENS
    public static final String XSDDATATYPENS
    XSDNAMESPACE
    public static final String XSDNAMESPACE
    XSDRECNS
    public static final String XSDRECNS
    XSDRECTYPENS
    public static final String XSDRECTYPENS
    XSI2000NS
    public static final String XSI2000NS
    XSINAMESPACE
    public static final String XSINAMESPACE
    XSIRECNS
    public static final String XSIRECNS

## XSDValidator Class

XSDValidator validates an instance XML document against an XMLSchema.

When registered, an XSDValidator object is inserted as a pipe-line node between XMLParser and XMLDocument events handler (SAXHandler or DOMBuilder). It works with three events: `startElement()`, `characters()` and `endElement()`. If defined, default element and default attribute values are added to the events contents as XMLSchema additions to infoset, and are propagated upwards.

The XMLSchema object is a set or group of element declarations:

         [element(name)] -> [shode(min/maxOccurs)] -> [type(group/simpleType)]

XSDValidator is implemented as stack based state machine. Each state represents element type - `group` or `simpleType`.

XMLSchema object, as a group, is loaded as a first state. Current `element` is matched against current state group elements. If matched the element type element name and snode info are loaded as new state.

In a case of group, a vector of `counters` is allocated in a parallel stack. This vector is used to count element occurrences.

State status could be:

- `NEW_STATE`: just loaded and not tried.

- `ACCEPTED:` `minOccurs` satisfied. Could still accept element occurrences.

- `DONE`: `maxOccurs` satisfied. Doesn't accept element occurrences.

Text element contents, or event characters, are matched against `simpleType` through method `validateValue()`. End element, found through event `endElement()`, is matched against the last named state.

XMLSchema attributes are represented as a group (`attrName -> attrType`) forming the contents of special element: `<_attrTag> attrType`. XMLParser converts attributes, found through event `startElement()`, accordingly.

XSDAny objects are used as Namespace frame descriptors.

Fake states are loaded in a case of error or when wildcard('any') contents is skipped.

#### Syntax

    public class XSDValidator

##### Table 5-14 Summary of Methods of XSDValidator

Method | Description
--- | ---
XSDValidator() | Class constructor.
characters() | Propagates notification of character data in elements.
endElement() | Receives notification of the end of an element.
setDocumentLocator() | Propagates Locator object for document events.
setError() | Sets an XMLError object as current err.
setXMLProperties() | Sets XML Properties for runtime properties.
setXMLProperty() | Sets a property.
startElement() | Receive notification of a beginning of the element.

## XSDValidator()

XSDValidator constructor.

#### Syntax

    public  XSDValidator();

## characters()

Propagate notification of character data inside an element. Throws `org.xml.sax.SAXException`. See also `org.xml.sax.DocumentHandler`

#### Syntax

    public void characters( char[] ch,
                            int start,
                            int length);

Parameter | Description
--- | ---
    ch
| The characters
    start
| The start position in the character array.
    length
| The number of characters to use from the character array.

## endElement()

Receive notification of the end of an element. Throws `org.xml.sax.SAXException`.

#### Syntax

    public void endElement( String namespaceURI,
                            String localName,
                            String qName);

Parameter | Description
--- | ---
    uri
| The Namespace URI, or the empty string if unavailable or no Namespace.
    localName
| The local name without prefix, or empty string if no Namespace processing.
    qName
| The qualified XML 1.0 name with prefix; empty string if not available.

## setDocumentLocator()

Propagates Locator object for document events. See also `org.xml.sax.DocumentHandler`, `org.xml.sax.Locator.`

#### Syntax

    public void setDocumentLocator( org.xml.sax.Locator locator);

Parameter | Description
--- | ---
    locator
| A locator for all SAX document events

## setError()

Sets an XMLError object as current err. Throws `org.xml.sax.SAXException`.

#### Syntax

    public void setError( oracle.xml.parser.v2.XMLError he);

Parameter | Description
--- | ---
    he
| XMLError object.

## setXMLProperties()

Sets XML Properties for runtime properties.

#### Syntax

    public void setXMLProperties( XMLProperties xmlProp);

Parameter | Description
--- | ---
    xmlProp
| XML properties.

## setXMLProperty()

Sets property value and returns the property. A null is returned if the property is read-only and cannot be set, or is not supported.

#### Syntax

    public Object setXMLProperty( java.lang.String name,
                                  java.lang.Object value);

Parameter | Description
--- | ---
    name
| name of the property
    value
| value of the property

## startElement()

Receives notification of the beginning of an element. Throws `org.xml.sax.SAXException`. See also: `org.xml.sax.Attributes`, `endElement().`

#### Syntax

    public void startElement( String namespaceURI,
                              String localName,
                              String qName,
                              Attributes atts);

Parameter | Description
--- | ---
    uri
| The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed
    localName
| The local name (without prefix), or the empty string if Namespace processing is not being performed.
    qName
| The qualified name with prefix; empty string if not available.
    atts
| The attributes attached to the element; empty object if no attributes.

| Copyright © 2001, 2003 Oracle Corporation. All Rights Reserved. |
Home | Contents | Index