Hi Daniel,

Daniel Jackson <[EMAIL PROTECTED]> writes:

> My program recieves as input an XML file. My goal is to check if this XML
> file passes schema validation. The XML file must contain 'xmlns'es. In the
> program I go over all the 'xmlns', that's how I know which schemas I need
> inorder to validate.
>
> After I collected all my xmlnses I go to that list and start searching the
> appropriate schemas.

Another alternative would simply be to pre-load all of your schemas
with loadGrammar (this would also involve creating in-memory "includer"
schemas for schemas with the same namespace) and then let the parser
figure out what to use. The advantage of this approach is that you
don't need to parse your XML documents twice.


> First problem is here. How do I know which schema to take? Suppose I have
> several schemas with the same target namespace, I can't know which schema is
> the one I need. So here the solution you proposed with the in-memory schema
> seems to fit. I just take all the schemas with the wanted target namespace
> and create a big one that includes the rest. I load this in-memory schema
> using loadGrammar. However when I try myparser.parse()... I get an error
> saying some element in the XML can't be found. That element is infact
> defined in one of the included schemas. I would expect the parser to call
> resolveEntity for the schemas referenced from the in-memory one but this
> doesn't happen. I tried messing with this abit and noticed that if I only
> set setExternalSchemaLocation without using loadGrammar I get several calls
> to resolveEntity, as expected - but this complicates things for me. What is
> the right way to handle this situation?

This should work. If you can send a small test case that reproduces this
then I will take a look.


> Suppose I don't have several schemas matching my 'xmlns'es. I use
> loadGrammar on all of the requested schemas and hit the parsing. Now my
> problem is abit different, what if a schema tries to include another schema?
> The include only has a schemaLocation attribute, which I can't rely on.

Well, if you can't rely on your schemas being complete/valid, then you
probably won't be able to validate an XML document against them. This
does not make much sense to me, though: how can you not rely on the
schemaLocation attributes inside the schemas that presumably came with
your application?

Boris

-- 
Boris Kolpackov, Code Synthesis Tools
Open source XML data binding for C++:   http://codesynthesis.com/products/xsd
Mobile/embedded validating XML parsing: http://codesynthesis.com/products/xsde

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

Reply via email to