You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Chad La Joie <la...@georgetown.edu> on 2007/02/11 05:08:20 UTC
XML schema validation through JAXP 1.3
I'm attempting to set up a JAXP 1.3 DocumentBuilderFactory that will
produce a DocumentBuilder that validates against a given Schema during
parsing. If I create a Schema object and set it on the Factory, create
a Builder from the Factory, and then parse a document I get the
following exception:
Document is invalid: no grammar found
Additional settings on the Factory include setting ignoreComments,
ingoreElementContentWhitespace, namespaceAware, and validating to true.
Also, "http://java.sun.com/xml/jaxp/properties/schemaSource" and
"http://java.sun.com/xml/jaxp/properties/schemaLanguage" are *not* set
as attributes.
However, if I do *not* set it on the Factory, create a parser, parser
the document, and *then* manually use that same Schema object to
validate the resultant Document, it validates correctly.
I searched the archives but all the references to this error I could
find involved setting the
"http://apache.org/xml/features/validation/schema" feature. However,
I'm trying to avoid implementation specific settings.
Can anyone offer some information on this problem? Certainly the JAXP
documentation [1] make it seem like all I have to do to turn on schema
parsing is set the Schema object on the Factory.
Thanks in advance.
[1]
http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setSchema(javax.xml.validation.Schema)
--
Chad La Joie 2052-C Harris Bldg
OIS-Middleware 202.687.0124
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: XML schema validation through JAXP 1.3
Posted by Chad La Joie <la...@georgetown.edu>.
That was it. I figured it was something simple I was missing. Thanks!
Michael Glavassevich wrote:
> Chad La Joie <la...@georgetown.edu> wrote on 02/10/2007 11:08:20 PM:
>
>> I'm attempting to set up a JAXP 1.3 DocumentBuilderFactory that will
>> produce a DocumentBuilder that validates against a given Schema during
>> parsing. If I create a Schema object and set it on the Factory, create
>> a Builder from the Factory, and then parse a document I get the
>> following exception:
>>
>> Document is invalid: no grammar found
>
> That error message comes from the DTD validator. If you set a Schema on
> the factory and set validating to true, you get both schema validation and
> DTD validation. I assume you only want schema validation, so you shouldn't
> be calling setValidating().
>
>> Additional settings on the Factory include setting ignoreComments,
>> ingoreElementContentWhitespace, namespaceAware, and validating to true.
>> Also, "http://java.sun.com/xml/jaxp/properties/schemaSource" and
>> "http://java.sun.com/xml/jaxp/properties/schemaLanguage" are *not* set
>> as attributes.
>>
>> However, if I do *not* set it on the Factory, create a parser, parser
>> the document, and *then* manually use that same Schema object to
>> validate the resultant Document, it validates correctly.
>>
>> I searched the archives but all the references to this error I could
>> find involved setting the
>> "http://apache.org/xml/features/validation/schema" feature. However,
>> I'm trying to avoid implementation specific settings.
>>
>> Can anyone offer some information on this problem? Certainly the JAXP
>> documentation [1] make it seem like all I have to do to turn on schema
>> parsing is set the Schema object on the Factory.
>>
>> Thanks in advance.
>>
>> [1]
>> http://java.sun.com/j2se/1.5.
>> 0/docs/api/javax/xml/parsers/DocumentBuilderFactory.
>> html#setSchema(javax.xml.validation.Schema)
>>
>> --
>> Chad La Joie 2052-C Harris Bldg
>> OIS-Middleware 202.687.0124
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
>> For additional commands, e-mail: j-users-help@xerces.apache.org
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
--
Chad La Joie 2052-C Harris Bldg
OIS-Middleware 202.687.0124
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org
Re: XML schema validation through JAXP 1.3
Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Chad La Joie <la...@georgetown.edu> wrote on 02/10/2007 11:08:20 PM:
> I'm attempting to set up a JAXP 1.3 DocumentBuilderFactory that will
> produce a DocumentBuilder that validates against a given Schema during
> parsing. If I create a Schema object and set it on the Factory, create
> a Builder from the Factory, and then parse a document I get the
> following exception:
>
> Document is invalid: no grammar found
That error message comes from the DTD validator. If you set a Schema on
the factory and set validating to true, you get both schema validation and
DTD validation. I assume you only want schema validation, so you shouldn't
be calling setValidating().
> Additional settings on the Factory include setting ignoreComments,
> ingoreElementContentWhitespace, namespaceAware, and validating to true.
> Also, "http://java.sun.com/xml/jaxp/properties/schemaSource" and
> "http://java.sun.com/xml/jaxp/properties/schemaLanguage" are *not* set
> as attributes.
>
> However, if I do *not* set it on the Factory, create a parser, parser
> the document, and *then* manually use that same Schema object to
> validate the resultant Document, it validates correctly.
>
> I searched the archives but all the references to this error I could
> find involved setting the
> "http://apache.org/xml/features/validation/schema" feature. However,
> I'm trying to avoid implementation specific settings.
>
> Can anyone offer some information on this problem? Certainly the JAXP
> documentation [1] make it seem like all I have to do to turn on schema
> parsing is set the Schema object on the Factory.
>
> Thanks in advance.
>
> [1]
> http://java.sun.com/j2se/1.5.
> 0/docs/api/javax/xml/parsers/DocumentBuilderFactory.
> html#setSchema(javax.xml.validation.Schema)
>
> --
> Chad La Joie 2052-C Harris Bldg
> OIS-Middleware 202.687.0124
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org