xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sandy...@ca.ibm.com
Subject Re: Accessing non-global attribute datatype information
Date Tue, 05 Nov 2002 14:12:37 GMT
I'm assuming you are using the latest Xerces.

XSDHandler is not intended to be used directly. This FAQ page [1] describes
how to load and cache grammars. The Schema page [2] might be interesting to
you too.

SchemaGrammar implements XSGrammar, which has a method "toXSModel" that
converts a SchemaGrammar to org.apache.xerces.impl.xs.psvi.XSModel. XSModel
has many methods to retrieve information about various components in your
schema. You can get basically everything you had in your schema, including
the data types of attributes.

[1] http://xml.apache.org/xerces2-j/faq-grammars.html
[2] http://xml.apache.org/xerces2-j/faq-xs.html

Cheers,
Sandy Gao
Software Developer, IBM Canada
(1-905) 413-3255
sandygao@ca.ibm.com



                                                                                         
                                             
                      eshell@imap3.asu.                                                  
                                             
                      edu                      To:       xerces-j-user@xml.apache.org    
                                             
                                               cc:                                       
                                             
                      11/05/2002 01:36         Subject:  Accessing non-global attribute datatype
information                           
                      AM                                                                 
                                             
                      Please respond to                                                  
                                             
                      xerces-j-user                                                      
                                             
                                                                                         
                                             
                                                                                         
                                             



Hello

I'm fairly new to the native interface and implementation APIs and have
been
having some difficulties. I have a schema we are using for the purpose of
representing the semantics of a
domain and also to validate whether fragments of non-xml text could be
marked
up as XML.  When we are parsing the schema and storing the elements as Java
objects in our data structure, I would like to be able to be able to
capture
the simple types as some Java object such as
org.apache.xerces.impl.xs.DateDV
and store that.

1)  Is there a way to access this kind of attribute datatype information
from a
SchemaGrammar, or by using some other method than using SchemaGrammars?
From
what I can see, you can't access the datatype information of attributes and
simple types that aren't globally declared using a SchemaGrammar, but maybe
I'm
missing something. It looks like this kind of information could be
retrieved
using xerces' dom's ASModel, but that is unfortuanately being deprecated.

2)  If there isn't a way and I'm stuck with temporarily using ASModels, do
you
have any idea how much longer they'll be in existance?

3)  I am also having my share of problems just getting the SchemaGrammar.
I
can get it using the DOMASModel, but getting it the straitforward way with
the
org.apache.xerces.impl.xs.traversers.XSDHandler, I end up getting null
pointer
exceptions after the parseSchema is called (no other other info from
stacktrace
besides that)

....
String filename = "sample.xsd";
             File schemaFile = new File(filename);
             Reader reader = new InputStreamReader(new
FileInputStream(schemaFile));
             XMLInputSource input = new XMLInputSource(null, filename,
null);
             input.setCharacterStream(reader);

             XSDDescription descr = new XSDDescription();
             descr.setTargetNamespace("http://www.oreilly.com/javaxml2");
             descr.setLiteralSystemId(filename);
             descr.setContextType(descr.CONTEXT_PREPARSE);
             descr.setLocationHints( new String[] { filename } );

             XSDHandler handler = new XSDHandler(new XSGrammarBucket());
             SchemaGrammar gramm = handler.parseSchema(input, descr, new
Hashtable
());


I have a feeling its my use of the XSDDescription thats at fault, because
when
I used another method on the XSDHandler that took the XSDDescription as an
argument, I got a null ptr exception again.  I tried about every
permutation
possible, setting or not setting various different system id's, which I
don't
entirely understand either (i.e. expanded, literal, base, all using the
filename for the file in the pwd), as well as location hints and enclosing
tag
which I have a feeling I don't need.

Any tips or sample code that could get me started with working with
SchemaGrammars or XSDDescriptions correctly?

Thank you in advance and sorry for the long letter,
Eric Shell

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





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


Mime
View raw message