Hitachi

uCosminexus Application Server XML Processor User Guide


6.10 Notes on the javax.xml.validation Package

The following table gives cautionary notes on the javax.xml.validation package.

Table 6‒20: Notes on the javax.xml.validation package

No.

Notes

1

In multi-thread programming, the SchemaFactory, Validator, ValidatorHandler, and TypeInfoProvider classes are not thread-safe. Therefore, make sure that each thread exclusively accesses these objects.

2

The URI "http://www.w3.org/2001/XMLSchema" is the only URI that you can specify as the argument of the newInstance(String schemaLanguage) method of the SchemaFactory class.

3

for the isSchemaLanguageSupported method of the SchemaFactory class.

Specify http://www.w3.org/2001/XMLSchema. If you specify other schema languages, this method returns false.

4

Specify a schema document with a different targetNamespace for each array element of the schemas argument for the newSchema(Source[] schemas) method of the SchemaFactory class. If you specify multiple schema documents with the same targetNamespace or with no targetNamespace, a schema document for an array element with a lower index is prioritized.

5

If you execute the newSchema(Source[] schemas) method of the SchemaFactory class under the following condition, exceptions may not occur:

  • Array elements for the schemas argument may include both valid schema documents and invalid ones.

To avoid this problem, use the following workaround:

  1. Save exception objects passed to the error and fatalError methods by the error handler for the SchemaFactory object.

  2. After calling the newSchema method, check for whether an exception object has been saved in step 1, and if it is successfully saved, throw the exception.

6

If you use a schema document including the definition for ID type attributes to validate XML documents by using the validate method of the Validator class, use either the validate(SAXSource), validate(DOMSource), or validate(SAXSource, SAXResult) method rather than the validate(DOMSource, DOMResult) method.

7

When all of the following conditions are met, if you execute the validate(Source source, Result result) method of the Validator class, a DOMException may occur:

  1. The result argument is a DOMResult object.

  2. The DOM node that includes the result tree set in the DOMResult object is the Document object with child nodes.

Therefore, make sure that the Document object described in condition 2 does not have any child node.

8

If a schema document includes the xsd:ENTITY type or xsd:ENTITIES type, schema validation by using the ValidatorHandler class is not supported. In such cases, perform the schema validation by using other methods such as the Validator class.

9

If the validation fails, a TypeInfo object obtained from the element or attribute that is not defined in the schema document becomes the same as the TypeInfo object of the xsd:anyType type.

10

If you specify the DOMSource object for the Source argument of the validate(Source) and validate(Source, Result) of the Validator class, make sure that the Node object owned by the DOMSource object meets all of the following conditions:

  1. Generated by the parser with the namespace enabled.

    For example, the DocumentBuilder generated by the DocumentBuilderFactory applied with setNamespaceAware(true).

  2. Generated by the parser without validation.

    For example, the DocumentBuilder generated by the DocumentBuilderFactory applied with setValidating (false).

11

If you specify the SAXSource object for the Source argument of the validate(Source) and validate(Source, Result) of the Validator class and the SAXSource object uses the XMLReader object, the XMLReader object must meet all of the following conditions:

  1. The object is an XMLReader object with the namespace enabled.

    For example, the XMLReader object taken out of the SAXParser that is generated by the SAXParserFactory applied with setNamespaceAware(true).

  2. The object is an XMLReader object without validation.

    For example, the XMLReader object taken out of the SAXParser that is generated by the SAXParserFactory applied with setValidating (false).

12

When all of the following conditions come in succession, the exception DOMException with the exception code NO_MODIFICATION_ALLOWED_ERR might occur:

  1. The DOMSource object is specified in the newSchema(Source) and newSchema(Source[])arguments of the SchemaFactory class, and these methods are executed.

  2. The DOM tree wrapping the DOMSource object specified in condition 1. is updated.

13

Using the newSchema method of the javax.xml.validation.SchemaFactory class, if you want to specify a SAXSource with an XMLReader specified, the XMLReader to be specified must satisfy the following conditions:

  • true is specified for the value of the SAX2 feature http://xml.org/sax/features/namespace-prefixes.

14

When you specify StAXSource and StAXResult in an argument of the validate(Source, Result) method of the Validator class, specify the same encoding in StAXSource and StAXResult.

15

Condition

When the getElementTypeInfo() method of the javax.xml.validation. TypeInfoProvider class is executed in the endElement event of ContentHandler set in ValidatorHandler.

Operation of Cosminexus XML Processor

The IllegalStateException exception is thrown. The TypeInfo object is not returned.