[xsd-users] xsd questions
Boris Kolpackov
boris at codesynthesis.com
Mon Oct 10 03:40:55 EDT 2005
Graham,
Graham Bennett <graham-xsd at simulcra.org> writes:
> It seems that the generated code parses instance documents with xerces
> validation enabled. Is it possible to disable this, which would remove
> the overhead of validation for each instance document,
Not yet, but I am planning to add such a flag in the next version (due in
a week or so).
> or is the code making assumptions that the document is always valid?
> Other implementations I have seen generate a 'perfect parser' for the
> document, which means the elements expected at each stage are hard coded
> in the generated code and an exception will be thrown if anything else
> is encountered.
xsd does generate a schema-specific parser and it does throw if an
unexpected element is encountered. I wouldn't call it a "perfect
parser" because there is much more to the Schema than simply which
elements are expected. I also very much doubt it that there is an
implementation that covers every aspect of Schema in the generated
code (imagine what the footprint alone is going to be).
So to summarize:
* yes, xsd expects valid documents
* yes, xsd has some number of checks in the generated code that do
not hurt the performance or the footprint (that's the criteria
we use when deciding whether the check should be there)
> The second question is a side-effect of the behaviour described above.
> In my environment we rarely specify schema location via the
> schemaLocation attribute in the instance document, but instead prefer to
> specify it externally on the parser (e.g. Xerces setSchemaLocation). Is
> there a way to get xsd to make the generated code 'remember' the schema
> location and set it on the parser when creating instances?
No, there is no such option. But that's an interesting idea. I think
it would be better to just have an additional argument to the parsing
functions that allows one to specify the schema location.
> Alternatively is there a way to get at the xerces internals to set
> it manually?
Sure. One of the parsing functions has the following signature:
name (xercesc::DOMDocument const&)
which allows you to set up the instance->dom stage in any way you
want. For example, you can create a parser, cache the schema (via
loadGrammar), and then parse multiple documents with this parser.
hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20051010/784f2394/attachment.pgp
More information about the xsd-users
mailing list