Hi,

I'm examining the grammar from a schema and am able to get all the complex
types, element declarations, etc. but for some reason the grammar does not
contain the annotations (i.e., the getAnnotation method always returns
null!). Below I have a code snippet which demonstrates how I am loading a
schema and getting the grammar. I was thinking that I needed to set some
feature and/or property but it isn't clear from looking at the FAQs. For
example, suppose I have a complex type definition and do something like
this:

XSObjectList annotations = pComplexTypeDefinition.getAnnotations ();
if (annotations != null)
{
        for (int i = 0; i < annotations.getLength (); i++)
        {
                (XSAnnotation) annotation = (XSAnnotation) annotations.item (i);
                System.out.println ("\"" + annotation.getAnnotationString() + 
"\"");
        }
}

Looking at org.apache.xerces.impl.xs.psvi.XSAnnotation there are only 2
methods (plus the general purpose methods inherited from XSObject):
        1. public java.lang.String getAnnotationString()
        2. public boolean writeAnnotation(java.lang.Object target, short
targetType)

Assuming I could get a non-null XSAnnotation object, could I use the
writeAnnotation method above to get at the appinfo element and its child
elements as below?

<?xml version = "1.0" ?>
        <schema xmlns = "http://www.w3.org/2001/XMLSchema";
          targetNamespace = "http://www.example.com/Test";
          xmlns:testNamespace = "http://www.example.com/Test";>

        <element name = "Customer">
                <complexType>
                        <annotation>
                                <documentation>
                                        Test annotation
                                </documentation>
                                <appinfo>
                                        <otherElement1 name="testing1"/>
                                        <otherElement2 name="testing2"/>
                                        <otherElement3 name="testing3"/>
                                </appinfo>
                        </annotation>
                        <choice>
                                <element name = "FirstName" type = "string" />
                                <element name = "MiddelInitial" type = "string" 
/>
                                <element name = "LastName" type = "string" />
                        </choice>
                </complexType>
        </element>

</schema>


    // code snippet to load schema and pull in grammar...
    XMLSchemaLoader xmlSchemaLoader = new XMLSchemaLoader();
     xmlSchemaLoader.setErrorHandler (this);

     XMLInputSource xmlInputSource = new XMLInputSource (null, schemaFile.
       getName (), schemaFile.toURI ().getPath ());

     FileInputStream inputStream = null;
     try
     {
        inputStream = new FileInputStream (schemaFile);
     }
     catch (Exception pException) { pException.printStackTrace (); }

     xmlInputSource.setByteStream (inputStream);

     XSGrammar schemaGrammar = null;
     try
     {
                schemaGrammar = (XSGrammar) xmlSchemaLoader.loadGrammar (
                  xmlInputSource);
                XSModel schemaModel = schemaGrammar.toXSModel();

                // process schema model...
      }
      catch (Exception pException)
      {
         pException.printStackTrace ();
      }


// I also tried a different way for getting the grammar and still no luck
getting annotations:
        XMLGrammarPreparser preparser = new XMLGrammarPreparser(sym);
        XMLGrammarPoolImpl grammarPool = new XMLGrammarPoolImpl();
        preparser.registerPreparser(XMLGrammarDescription.XML_SCHEMA, null);

        preparser.setProperty(GRAMMAR_POOL, grammarPool);
        preparser.setFeature(NAMESPACES_FEATURE_ID, true);
        preparser.setFeature(VALIDATION_FEATURE_ID, true);
        // note we can set schema features just in case...
        preparser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, true);
        preparser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, 
schemaFullChecking);
        // parse the grammar...

        try
        {
                Grammar grammar =
preparser.preparseGrammar(XMLGrammarDescription.XML_SCHEMA,
                  stringToXIS(pSchemaFile.toURI ().getPath ()));

                XSGrammar schemaGrammar = (XSGrammar) grammar;

                XSModel schemaModel = schemaGrammar.toXSModel();

                // process schema model...
        }
        catch (Exception pException)
        {
                 pException.printStackTrace ();
        }

Thanks.

_____________________________________________
Karl R. Mueller
[EMAIL PROTECTED]
_____________________________________________



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to