Hi,
I'd like to know if it is possible to get access to
the java schema representation
(Schema Grammar object) by using the xerces parsers
(SAX or DOM).
I actually want to use this java object for
dynamically creating code, gui and other
stuff...
I don' t like to parse my schema file, and to
traverse my schema DOM if already,
it exits a java representation of
it...!!
I have tried with the following code to access the
SchemaGrammar but I failed ...
the main of my testing
class:
WHIPSAXParser parser = new
WHIPSAXParser();
XMLValidator validator = parser.getValidator();
GrammarResolver gr = new GrammarResolverImpl();
validator.setGrammarResolver(gr);
try
{
validator.setSchemaValidationEnabled( true );
validator.setDynamicValidationEnabled( true );
validator.setNamespacesEnabled( true );
validator.setValidationEnabled( true );
}
catch( Exception e )
{
e.printStackTrace();
}
XMLValidator validator = parser.getValidator();
GrammarResolver gr = new GrammarResolverImpl();
validator.setGrammarResolver(gr);
try
{
validator.setSchemaValidationEnabled( true );
validator.setDynamicValidationEnabled( true );
validator.setNamespacesEnabled( true );
validator.setValidationEnabled( true );
}
catch( Exception e )
{
e.printStackTrace();
}
InputSource source =
...
try
{
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
parser.parse( source );
}
catch (SAXNotRecognizedException snre)
{
snre.printStackTrace();
}
catch (SAXNotSupportedException snse)
{
snse.printStackTrace();
}
catch( IOException ioe )
{
ioe.printStackTrace();
}
catch( SAXException saxe )
{
saxe.printStackTrace();
}
try
{
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
parser.parse( source );
}
catch (SAXNotRecognizedException snre)
{
snre.printStackTrace();
}
catch (SAXNotSupportedException snse)
{
snse.printStackTrace();
}
catch( IOException ioe )
{
ioe.printStackTrace();
}
catch( SAXException saxe )
{
saxe.printStackTrace();
}
String nsKey =
null;
Enumeration enum = gr.nameSpaceKeys();
while( enum.hasMoreElements() )
{
nsKey = (String) enum.nextElement();
System.out.println( "name space key : " + nsKey );
}
Enumeration enum = gr.nameSpaceKeys();
while( enum.hasMoreElements() )
{
nsKey = (String) enum.nextElement();
System.out.println( "name space key : " + nsKey );
}
And my parser wrapper
class:
public class WHIPSAXParser extends
SAXParser
{
public XMLValidator getValidator()
{
return fValidator;
}
}
{
public XMLValidator getValidator()
{
return fValidator;
}
}
I don't get anything from my XML files ... no
namespaces ...
Where am I wrong ?
If someone knows how to get the schema grammar
object, I very very interested ...!!!
Many thanks
Jean-Guillaume LALANNE
ps: another quick question : how to validate a DOM
object against a schema (stream) ???
----- Original Message -----
From: "Umesh Subramanian" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 15, 2001 3:45 PM
Subject: schema validator
caching
> Is it possible (or planned in future releases of xerces) to cache the
> schema validator objects, once the schema is loaded? In my application,
> I expect to validate XML instances of the same schema many times over
> and would like to reduce the overhead of reading the schema file
> everytime.
> Thanks
> -Umesh
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
