You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Chris Greenlee <CG...@demandsolutions.com> on 2003/02/17 22:15:42 UTC
Schema validation
Greetings!
I'm attempting to validate a very small XML document against a very small
schema, without specifying it internally. Here's my code:
-------begin-------
MyHandler handler;
SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();
XMLCh *propertyValue = XMLString::transcode("myschema.xsd");
ArrayJanitor<XMLCh> propertyValueJanitor(propertyValue);
std::auto_ptr<SAX2XMLReader> safeReader(reader);
safeReader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
safeReader->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
safeReader->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
safeReader->setFeature(XMLUni::fgXercesSchema, true);
safeReader->setFeature(XMLUni::fgSAX2CoreValidation, true);
safeReader->setFeature(XMLUni::fgXercesDynamic, false);
safeReader->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
propertyValue);
safeReader->setContentHandler(&handler);
safeReader->setErrorHandler(&handler);
safeReader->parse("myxml.xml");
-------end-------
This doesn't work at all; no validation occurs as far as I can tell. In
fact, I can delete the XSD file without any errors showing up. I can
mangle the XML file horribly and it doesn't care (with or without an XSD
sitting there). The XML file is definitely being parsed. What am I doing
wrong?
Cheers,
Chris Greenlee
cgreenlee@demandsolutions.com
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Schema validation
Posted by Chris Greenlee <CG...@demandsolutions.com>.
Gareth,
That occurred to me late last night, and was indeed my problem. However,
I would have thought that xerces would throw a fatal error if the schema
file it was being told to validate against did not exist. That silent
failure confused me into thinking it wasn't attempting to validate at all.
Is there a reason that isn't considered a fatal error (given the features
I've enabled/disabled)?
Thanks for the help!
Cheers,
Chris Greenlee
> Hi,
> have you overridden the methods to report errors in your handler?
> Check out SAX2Print for an example.
>
> Gareth
>
>
>
> On Mon, 17 Feb 2003, Chris Greenlee wrote:
>
>> Greetings!
>>
>> I'm attempting to validate a very small XML document against a very
>> small schema, without specifying it internally. Here's my code:
>>
>> -------begin-------
>> MyHandler handler;
>> SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();
>> XMLCh *propertyValue = XMLString::transcode("myschema.xsd");
>> ArrayJanitor<XMLCh> propertyValueJanitor(propertyValue);
>> std::auto_ptr<SAX2XMLReader> safeReader(reader);
>>
>> safeReader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
>> safeReader->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
>> safeReader->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
>> safeReader->setFeature(XMLUni::fgXercesSchema, true);
>> safeReader->setFeature(XMLUni::fgSAX2CoreValidation, true);
>> safeReader->setFeature(XMLUni::fgXercesDynamic, false);
>> safeReader->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
>> propertyValue);
>> safeReader->setContentHandler(&handler);
>> safeReader->setErrorHandler(&handler);
>>
>> safeReader->parse("myxml.xml");
>> -------end-------
>>
>> This doesn't work at all; no validation occurs as far as I can tell.
>> In fact, I can delete the XSD file without any errors showing up. I
>> can mangle the XML file horribly and it doesn't care (with or without
>> an XSD sitting there). The XML file is definitely being parsed. What
>> am I doing wrong?
>>
>> Cheers,
>>
>> Chris Greenlee
>> cgreenlee@demandsolutions.com
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
>> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>>
>>
>
> --
> Gareth Reakes, Head of Product Development +44-1865-203192
> DecisionSoft Limited http://www.decisionsoft.com
> XML Development and Services
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
Re: Schema validation
Posted by Gareth Reakes <ga...@decisionsoft.com>.
Hi,
have you overridden the methods to report errors in your handler?
Check out SAX2Print for an example.
Gareth
On Mon, 17 Feb 2003, Chris Greenlee wrote:
> Greetings!
>
> I'm attempting to validate a very small XML document against a very small
> schema, without specifying it internally. Here's my code:
>
> -------begin-------
> MyHandler handler;
> SAX2XMLReader* reader = XMLReaderFactory::createXMLReader();
> XMLCh *propertyValue = XMLString::transcode("myschema.xsd");
> ArrayJanitor<XMLCh> propertyValueJanitor(propertyValue);
> std::auto_ptr<SAX2XMLReader> safeReader(reader);
>
> safeReader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
> safeReader->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
> safeReader->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
> safeReader->setFeature(XMLUni::fgXercesSchema, true);
> safeReader->setFeature(XMLUni::fgSAX2CoreValidation, true);
> safeReader->setFeature(XMLUni::fgXercesDynamic, false);
> safeReader->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
> propertyValue);
> safeReader->setContentHandler(&handler);
> safeReader->setErrorHandler(&handler);
>
> safeReader->parse("myxml.xml");
> -------end-------
>
> This doesn't work at all; no validation occurs as far as I can tell. In
> fact, I can delete the XSD file without any errors showing up. I can
> mangle the XML file horribly and it doesn't care (with or without an XSD
> sitting there). The XML file is definitely being parsed. What am I doing
> wrong?
>
> Cheers,
>
> Chris Greenlee
> cgreenlee@demandsolutions.com
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
--
Gareth Reakes, Head of Product Development +44-1865-203192
DecisionSoft Limited http://www.decisionsoft.com
XML Development and Services
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org