You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by 4p...@sneakemail.com on 2007/01/03 00:22:46 UTC

validating XML Schema files

Hello folks,

My application processes XML Schema files on the DOM level (.xsd files are parsed with XercesDOMParser::parse()). However, to detect user errors in the schema files, I'd like to turn on validation for them.

Is that at all possible?

I ran some tests with the schema for schemas, which XercesDOMParser rejects (I assume that's because its built-in types are redefined). I also tried to feed the schema DTD into the parser, without success (Xerces seems to expect a schema rather than a DTD when it requests a resource for a namespace identifier)

Can anyone point me into the right direction?

I can post my test code as well if that helps.

Cheers,

Uwe



--------------------------------------
Protect yourself from spam, 
use http://sneakemail.com

Re: validating XML Schema files

Posted by 4p...@sneakemail.com.
Hi Alberto (and all you other folks who might be reading this),

Just a quick follow up with thanks for the help ;)

Validating XML Schema schema documents actually works with Xerces C if 
you use W3C's DTD. I can also confirm your findings, it seems impossible 
to validate with W3C's schema (and probably any other because of the 
namespace issue).

I actually wrote a special InputStream that stitches a <!DOCTYPE ...> in 
front of an XML document if there is none, which comes quite handy for 
the typical schema (most examples come without one).

With this, schema validation works fine in my test driver.

Thanks again for the pointers, they were a great help!

Cheers,

Uwe


Alberto Massari amassari-at-datadirect.com |xerces-c-users mailing list| 
schrieb:
> At 10.05 03/01/2007 +0100, 4pzbrog02@sneakemail.com wrote:
>> Thanks for the response :)
>>
>> -- 
>> > The only way you can test for a grammar to be valid is by loading 
>> it using loadGrammar.
>> > Using the DTD or the XMLSchema provided by the specs will in any 
>> case result in less validation checks than the ones listed in the 
>> specs itself.
>> -- 
>>
>> Hmm, but then I need to load it twice, once as DOM, and once as 
>> grammar. I could live with less checks, however, I want to catch 
>> things like elements that are in the wrong place or wrongly spelt 
>> attributes that my DOM scanning code doesn't see because its not 
>> looking for such errors.
>>
>> Is there a way to validate a Schema directly via DTD or Schema, 
>> without using loadGrammar?
>
> I tried once to validate a schema using a reduced version of the XSD 
> for XMLSchema, and I gave up (after removing the definitions of the 
> built-in simple types, I think I got stuck with the fact that the 
> XMLSchema namespace is already known to Xerces); you may have better 
> luck using the DTD, but you will have to change the schema file to add 
> the DOCTYPE instruction.
>
> Good luck,
> Alberto
>
>
>> Cheers,
>>
>> Uwe
>>
>> Alberto Massari amassari-at-datadirect.com |xerces-c-users mailing 
>> list| schrieb:
>>> Hi Uwe,
>>>
>>> At 23.22 02/01/2007 +0000, 4pzbrog02@sneakemail.com wrote:
>>>> Hello folks,
>>>>
>>>> My application processes XML Schema files on the DOM level (.xsd 
>>>> files are parsed with XercesDOMParser::parse()). However, to detect 
>>>> user errors in the schema files, I'd like to turn on validation for 
>>>> them.
>>>>
>>>> Is that at all possible?
>>>
>>> The only way you can test for a grammar to be valid is by loading it 
>>> using loadGrammar.
>>> Using the DTD or the XMLSchema provided by the specs will in any 
>>> case result in less validation checks than the ones listed in the 
>>> specs itself.
>>>
>>> Alberto
>>>
>>>
>>>> I ran some tests with the schema for schemas, which XercesDOMParser 
>>>> rejects (I assume that's because its built-in types are redefined). 
>>>> I also tried to feed the schema DTD into the parser, without 
>>>> success (Xerces seems to expect a schema rather than a DTD when it 
>>>> requests a resource for a namespace identifier)
>>>>
>>>> Can anyone point me into the right direction?
>>>>
>>>> I can post my test code as well if that helps.
>>>>
>>>> Cheers,
>>>>
>>>> Uwe
>>>>
>>>>
>>>>
>>>> --------------------------------------
>>>> Protect yourself from spam,
>>>> use http://sneakemail.com
>


Re: validating XML Schema files

Posted by Alberto Massari <am...@datadirect.com>.
At 10.05 03/01/2007 +0100, 4pzbrog02@sneakemail.com wrote:
>Thanks for the response :)
>
>--
> > The only way you can test for a grammar to be valid is by loading 
> it using loadGrammar.
> > Using the DTD or the XMLSchema provided by the specs will in any 
> case result in less validation checks than the ones listed in the specs itself.
>--
>
>Hmm, but then I need to load it twice, once as DOM, and once as 
>grammar. I could live with less checks, however, I want to catch 
>things like elements that are in the wrong place or wrongly spelt 
>attributes that my DOM scanning code doesn't see because its not 
>looking for such errors.
>
>Is there a way to validate a Schema directly via DTD or Schema, 
>without using loadGrammar?

I tried once to validate a schema using a reduced version of the XSD 
for XMLSchema, and I gave up (after removing the definitions of the 
built-in simple types, I think I got stuck with the fact that the 
XMLSchema namespace is already known to Xerces); you may have better 
luck using the DTD, but you will have to change the schema file to 
add the DOCTYPE instruction.

Good luck,
Alberto


>Cheers,
>
>Uwe
>
>Alberto Massari amassari-at-datadirect.com |xerces-c-users mailing 
>list| schrieb:
>>Hi Uwe,
>>
>>At 23.22 02/01/2007 +0000, 4pzbrog02@sneakemail.com wrote:
>>>Hello folks,
>>>
>>>My application processes XML Schema files on the DOM level (.xsd 
>>>files are parsed with XercesDOMParser::parse()). However, to 
>>>detect user errors in the schema files, I'd like to turn on 
>>>validation for them.
>>>
>>>Is that at all possible?
>>
>>The only way you can test for a grammar to be valid is by loading 
>>it using loadGrammar.
>>Using the DTD or the XMLSchema provided by the specs will in any 
>>case result in less validation checks than the ones listed in the specs itself.
>>
>>Alberto
>>
>>
>>>I ran some tests with the schema for schemas, which 
>>>XercesDOMParser rejects (I assume that's because its built-in 
>>>types are redefined). I also tried to feed the schema DTD into the 
>>>parser, without success (Xerces seems to expect a schema rather 
>>>than a DTD when it requests a resource for a namespace identifier)
>>>
>>>Can anyone point me into the right direction?
>>>
>>>I can post my test code as well if that helps.
>>>
>>>Cheers,
>>>
>>>Uwe
>>>
>>>
>>>
>>>--------------------------------------
>>>Protect yourself from spam,
>>>use http://sneakemail.com


Re: validating XML Schema files

Posted by 4p...@sneakemail.com.
Thanks for the response :)

--
 > The only way you can test for a grammar to be valid is by loading it 
using loadGrammar.
 > Using the DTD or the XMLSchema provided by the specs will in any case 
result in less validation checks than the ones listed in the specs itself.
--

Hmm, but then I need to load it twice, once as DOM, and once as grammar. 
I could live with less checks, however, I want to catch things like 
elements that are in the wrong place or wrongly spelt attributes that my 
DOM scanning code doesn't see because its not looking for such errors.

Is there a way to validate a Schema directly via DTD or Schema, without 
using loadGrammar?

Cheers,

Uwe

Alberto Massari amassari-at-datadirect.com |xerces-c-users mailing list| 
schrieb:
> Hi Uwe,
>
> At 23.22 02/01/2007 +0000, 4pzbrog02@sneakemail.com wrote:
>> Hello folks,
>>
>> My application processes XML Schema files on the DOM level (.xsd 
>> files are parsed with XercesDOMParser::parse()). However, to detect 
>> user errors in the schema files, I'd like to turn on validation for 
>> them.
>>
>> Is that at all possible?
>
> The only way you can test for a grammar to be valid is by loading it 
> using loadGrammar.
> Using the DTD or the XMLSchema provided by the specs will in any case 
> result in less validation checks than the ones listed in the specs 
> itself.
>
> Alberto
>
>
>> I ran some tests with the schema for schemas, which XercesDOMParser 
>> rejects (I assume that's because its built-in types are redefined). I 
>> also tried to feed the schema DTD into the parser, without success 
>> (Xerces seems to expect a schema rather than a DTD when it requests a 
>> resource for a namespace identifier)
>>
>> Can anyone point me into the right direction?
>>
>> I can post my test code as well if that helps.
>>
>> Cheers,
>>
>> Uwe
>>
>>
>>
>> --------------------------------------
>> Protect yourself from spam,
>> use http://sneakemail.com
>


Re: validating XML Schema files

Posted by Alberto Massari <am...@datadirect.com>.
Hi Uwe,

At 23.22 02/01/2007 +0000, 4pzbrog02@sneakemail.com wrote:
>Hello folks,
>
>My application processes XML Schema files on the DOM level (.xsd 
>files are parsed with XercesDOMParser::parse()). However, to detect 
>user errors in the schema files, I'd like to turn on validation for them.
>
>Is that at all possible?

The only way you can test for a grammar to be valid is by loading it 
using loadGrammar.
Using the DTD or the XMLSchema provided by the specs will in any case 
result in less validation checks than the ones listed in the specs itself.

Alberto


>I ran some tests with the schema for schemas, which XercesDOMParser 
>rejects (I assume that's because its built-in types are redefined). 
>I also tried to feed the schema DTD into the parser, without success 
>(Xerces seems to expect a schema rather than a DTD when it requests 
>a resource for a namespace identifier)
>
>Can anyone point me into the right direction?
>
>I can post my test code as well if that helps.
>
>Cheers,
>
>Uwe
>
>
>
>--------------------------------------
>Protect yourself from spam,
>use http://sneakemail.com