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 Alexi Zuo <al...@gmail.com> on 2008/06/10 08:32:23 UTC

SAX2 XML validation against schema without targetNamespace

HI, I am trying to use Xerces C++ 2.2 to validate xml against an
external schema, and this external schema may be from memory. So the input
pamameter is an InputSource object. So I have to use
SAX2XMLReader::loadGrammar() to load the schema ( I can't use
SAX2XMLReader::setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,...).
The schema does not specify "targetNamespace", and the xml file does not
specify namespace either.  The following code can't pass validation with
Xerces 2.2 library, but CAN pass with Xerces 2.8 library.

Can anybody tell me what I can do? I can only use Xerces C++2.2 library.

  SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();

 parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
 parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
  parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
 DefaultHandler handler;
 MySAX2Handler error_handler;

 parser->setContentHandler(&handler);
 parser->setErrorHandler(&error_handler);
 parser->setEntityResolver(&handler);

 parser->loadGrammar(*inputSchema*, Grammar::SchemaGrammarType, true);

  parser->parse(xmlFile.c_str());

Re: SAX2 XML validation against schema without targetNamespace

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Alexi,

Alexi Zuo <al...@gmail.com> writes:

> Thanks. In fact, In fact, I am not sure if it is a bug or just I don't
> know how to use it correctly.

If the same code works in 2.8.0 and doesn't in 2.2.0, then there is a
good chance 2.2.0 has a bug. You can also try to run one of the examples
(e.g., SAX2Count) that comes with 2.2.0 on your XML and schema files
with the assumption that the example does things properly.

Boris

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

Re: SAX2 XML validation against schema without targetNamespace

Posted by Alexi Zuo <al...@gmail.com>.
Thanks. In fact, In fact, I am not sure if it is a bug or just I don't know
how to use it correctly.

On 6/12/08, Boris Kolpackov <bo...@codesynthesis.com> wrote:
>
> Hi Alexi,
>
> Alexi Zuo <al...@gmail.com> writes:
>
> > The following code can't pass validation with Xerces 2.2 library, but
> > CAN pass with Xerces 2.8 library.
>
> I don't think any of the Xerces-C++ developers will be debugging more
> that 5 years-old release. I suggest that you either upgrade to the
> latest release or identify the earliest release in which this has
> been fixed and try to backport it to 2.2.0.
>
> Boris
>
> --
> Boris Kolpackov, Code Synthesis Tools
> http://codesynthesis.com/~boris/blog
> Open source XML data binding for C++:
> http://codesynthesis.com/products/xsd
> Mobile/embedded validating XML parsing:
> http://codesynthesis.com/products/xsde
>

Re: SAX2 XML validation against schema without targetNamespace

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi Alexi,

Alexi Zuo <al...@gmail.com> writes:

> The following code can't pass validation with Xerces 2.2 library, but
> CAN pass with Xerces 2.8 library.

I don't think any of the Xerces-C++ developers will be debugging more
that 5 years-old release. I suggest that you either upgrade to the
latest release or identify the earliest release in which this has
been fixed and try to backport it to 2.2.0.

Boris

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

Re: SAX2 XML validation against schema without targetNamespace

Posted by Alexi Zuo <al...@gmail.com>.
>
>  HI, I am trying to use Xerces C++ 2.2 to validate xml against an
> external schema, and this external schema may be from memory. So the input
> pamameter is an InputSource object. So I have to use
> SAX2XMLReader::loadGrammar() to load the schema ( I can't use
> SAX2XMLReader::setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,...).
> The schema does not specify "targetNamespace", and the xml file does not
> specify namespace either.  The following code can't pass validation with
> Xerces 2.2 library, but CAN pass with Xerces 2.8 library.
>
> Can anybody tell me what I can do? I can only use Xerces C++2.2 library.
>
>   SAX2XMLReader* parser = XMLReaderFactory::createXMLReader();
>
>  parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
>  parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
>   parser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, true);
>  DefaultHandler handler;
>  MySAX2Handler error_handler;
>
>  parser->setContentHandler(&handler);
>  parser->setErrorHandler(&error_handler);
>  parser->setEntityResolver(&handler);
>
>  parser->loadGrammar(*inputSchema*, Grammar::SchemaGrammarType, true);
>
>   parser->parse(xmlFile.c_str());
>