Hi all,
As some of you might be remembering, that I started to implement
XML Schema 1.1 assertions into Xerces. Since last few days,
I have started to put an effort again to complete the Xerces
assertions support.
I am happy to share that, Ken Cai is working with me on assertions
implementation.
We are sending this mail to the xerces-j-dev community, to share the
"assertions design" thoughts so far. It would be great, if any one
would like to suggest any improvements, or has any thoughts about
assertions implementation.
The assertions traversal code is written into Xerces and available at
the online SVN repository. The development of XPath 2.0 integration
code is underway. After the XPath 2.0 integration code is complete, a
complete assertions support in Xerces would be ready for use.
Ken has shared with me in a personal mail, a generic assertions
interface to the XPath 2.0 engine. This interface looks like
following:
public interface XMLAssert {
public void initXPathProcessor(Document xdmRoot) throws Exception;
public void initXPathProcessor(InputStream is) throws Exception, IOException;
public void setNamespace(String prefix, String uri);
public void setSchema(XSModel schema);
public void setValidating(boolean validate);
public boolean evaluateXpathExpression(String xpathExpression)
throws Exception;
}
For each specific XPath 2.0 engine, this interface needs to be
implemented. Ken has also written and shared with me, an
implementation of this interface, for the Psychopath XPath 2.0 engine.
I would be working to integrate Ken's code with the XPath 2.0
assertions code I am writing. We'll post all the newly written and
modified assertions code with a JIRA issue after some time (may be few
days later) (after ensuring good quality).
Currently, I am trying to modify the Xerces class,
"XMLSchemaValidator" to support assertions. The basic framework would
like
following:
public class XMLSchemaValidator .. { ...
// some stuff here
public void startElement(QName element, XMLAttributes attributes,
Augmentations augs) throws XNIException {
// some stuff here
XSTypeDefinition typeDef = fCurrentPSVI.getTypeDefinition();
if (typeDef.getTypeCategory() == XSTypeDefinition.COMPLEX_TYPE) {
XSComplexTypeDefinition complexTypeDef =
(XSComplexTypeDefinition) typeDef;
XSObjectList assertions = complexTypeDef.getAssertions();
if (assertions.getLength() > 0) {
// do something here
}
}
else if (typeDef.getTypeCategory() == XSTypeDefinition.SIMPLE_TYPE) {
XSSimpleTypeDefinition simpleTypeDef = (XSSimpleTypeDefinition) typeDef;
XSObjectList facets = simpleTypeDef.getMultiValueFacets();
for (int i = 0; i < facets.getLength(); i++) {
XSMultiValueFacet facet = (XSMultiValueFacet) facets.item(i);
if (facet.getFacetKind() == XSSimpleTypeDefinition.FACET_ASSERT) {
// do something here
}
}
}
// if assertions are present, start building an XML tree with this
element as
// a root of the tree.
// some stuff here
}
public void endElement(QName element, Augmentations augs)
throws XNIException {
// some stuff here
// end tree construction
// evaluate assertions on this tree. throw error if assertion
evaluation is false.
// some stuff here
}
public void characters(org.apache.xerces.xni.XMLString text,
org.apache.xerces.xni.Augmentations augs) .. {
// some stuff here
// write code here to add text nodes to the assertions XML tree.
// some stuff here
}
This is just a very high level design. The actual details in the final
code may take a different shape.
I'm hoping to have an initial complete assertions implementation quite
soon. Please watch this space :)
--
Regards,
Mukul Gandhi
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]