You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by "Dr. Michael Treichel" <Mi...@nterra.com> on 2003/01/16 13:07:28 UTC

Schema annotations

Dear all!

We would like help implementing access to schema annotations. How do we get
into business?

Best ... Michael

> We are having problems getting access to schema annotations using
Xerces-J.
> The following code snipplet returns a null value for
> schema.getAnnotations():

Access to the annotations is not implemented yet.. Hopefully we will
have time to do it in the next couple of months.
If you are willing to help with implementation, please email to
xerces-j-dev@xml.apache.org list.

Thank you,
--
Elena Litani / IBM Toronto



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Schema annotations

Posted by Elena Litani <el...@ca.ibm.com>.
Hi Michael, 

"Dr. Michael Treichel" wrote:
> We would like help implementing access to schema annotations. How do we get
> into business?

In general, we thought that annotation should be stored as an XML string
in each XML schema component (i.e
org.apache.xerces.impl.xs.XSElementDecl), following the XML syntax
defined in the XML Schema specification [1].
The writeAnnotation() will invoke SAX or DOM parser that will parse this
annotation string, issuing either SAX events or producing a DOM tree.

Here some additional information:
1. Traversing of annotation from the schema is done in the
org.apache.xerces.impl.xs.traversers XSDAbstractTraverser
traverseAnnotationDecl. The schemas are traversed into dom-like
structure (see implementation in org.apache.xerces.impl.xs.opti) but
traversal is implementation independent (see DOMUtil class). You will
need to walk the DTM tree (using DOMUtil) and create annotation string.
At this time you will also need to save all the namespace declarations
in scope (since you need those declarations to parse the string, etc...)
-- XSDocumentInfo has a pointer to the namespaces in scope. You need to
get all prefix declarations and add those as namespace declarations
(xmlns:prefix="http://...") to the xs:annotation. 
Btw, for serialization of the annotations you might look at
XMLSerializer (in org.apache.xml.serialize) -- there is a serializeNode
method, however I am not sure if it will work since it assumes DOM
implementation.

2. The DTM (org.apache.xerces.impl.xs.opti) implementation currently
does not create any text nodes, meaning that any text in <documentation>
or <appinfo> won't be available... To fix it you need to modify the
SchemaDOMParser (org.apache.xerces.impl.xs.opti) parser, to create
string when in context of annotation element. This could be done by
having a global StringBuffer, appending the data to it in characters()
method and retrieving / resetting data at start/endElement calls
(assuming there are no comments, PIs, etc in the annotation context).
The string could be later stored either as a Text node or just a string
field on the DefaultElement node (org.apache.xerces.impl.xs.opti).

2. In the writeAnnotation you will need to get a parser. For performance
reasons you might need to implement some kind of synchronized parser
pool to avoid creating a new parser for each writeAnnotation method
invocation. As far as I know, Xerces grammar implementation is
thread/safe (grammars could be added to different grammar pools used by
parsers in the different threads). So you must synchronize access to
your parser.

3. writeAnnotation allows you to serialize to DOM or SAX. Sax
implementation is trivial -- you only need to set correct
DocumentHandler on the SAXParser. For the DOM, you will need to make
some changes to be able to pass Document object to the DOMParser. As it
works now, AbstractDOMParser (org.apache.xerces.parsers) queries
document-class property in startDocument(..) method and creates an
appropriate document instance. You will need to modify this method to
allow using pre-set Document class -- the class could be either set via
a new public method or via new INTERNAL xerces property.

Let us know if you have more questions. 

[1] http://www.w3.org/TR/xmlschema-1/#declare-annotation


Hope it helps, 
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org