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 "Garner, Kenton (Mission Systems)" <Ke...@ngc.com> on 2006/03/28 00:59:12 UTC
Problem Serializing schema grammar to disk
I am trying to test the example provided by :
http://www-128.ibm.com/developerworks/webservices/library/x-xsdxerc.html
#code4
I am new to XERCES-C, and I can not get past the second line of code (
core dump ).
I would appreciate any help I could get. I have an immediate need for
this functionality and I would love to incorporate
It in my project.
OS: Solaris 8 (sparc)
XERCES-C v 2_7_0
Problem Code...
========================================================
// Include "common includes".
#include <xercesc/sax2/XMLReaderFactory.hpp>
#include <xercesc/sax2/SAX2XMLReader.hpp>
#include <xercesc/sax2/DefaultHandler.hpp>
// Handy definitions of constants.
#include <xercesc/util/XMLUni.hpp>
#include <xercesc/util/PlatformUtils.hpp>
// Various interfaces you'll need:
#include <xercesc/validators/common/Grammar.hpp>
#include <xercesc/framework/MemoryManager.hpp>
#include <xercesc/framework/XMLGrammarPool.hpp>
#include <xercesc/framework/BinOutputStream.hpp>
// Xerces-C++'s default MemoryManager/XMLGrammarPool implementations.
#include <xercesc/internal/MemoryManagerImpl.hpp>
#include <xercesc/internal/XMLGrammarPoolImpl.hpp>
// Binary output stream for files.
#include <xercesc/internal/BinFileOutputStream.hpp>
XERCES_CPP_NAMESPACE_USE
//
------------------------------------------------------------------------
---
// Program entry point
//
------------------------------------------------------------------------
---
int main(int argC, char* argV[])
{
// Create a memory manager instance for memory handling requests.
MemoryManager *memMgr = new MemoryManagerImpl();
// Create a grammar pool that stores the cached grammars.
XMLGrammarPool* pool = new XMLGrammarPoolImpl(memMgr);
// Create a SAX2 parser object.
SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(memMgr, pool);
// Set "common features".
parser->setFeature(XMLUni::fgSAX2CoreValidation, true); // Perform
Validat ion
parser->setFeature(XMLUni::fgXercesSchema, true); // Enable
Schema Support
parser->setFeature(XMLUni::fgXercesDynamic, false); // Disable
Validate Only when Grammar is specified
parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); // Enable
NameSpace Processing
parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true); // Enable
Full Schema Constraint Checking
// Enable grammar caching feature.
parser->setFeature(XMLUni::fgXercesCacheGrammarFromParse, true);
// Set errorHandler and entityResolver (no need for ContentHandler).
// You will use a default handler provided by Xerces-C++ (no op action).
// Users should write their own handlers and install them.
DefaultHandler handler;
parser->setErrorHandler(&handler);
parser->setEntityResolver(&handler);
// xsdFile1 could be a file path or
// of an object type xercesc/sax/InputSource.
parser->loadGrammar("genericAuxiliary.xsd", Grammar::SchemaGrammarType,
true);
// Include however many XSD files you might require.
// parser->loadGrammar("imp.xsd", Grammar::SchemaGrammarType, true);
// Create an output stream instance to serialize processed grammar
// to use a BinFileOutputStream instance to serialize data to disk.
BinOutputStream *outStream = new
BinFileOutputStream("schemaGrammar.pool");
// Serialize the grammar pool.
pool->serializeGrammars(outStream);
// Clean up.
delete parser;
delete pool;
delete outStream;
delete memMgr;
}
========================================================
Thanks In Advance,
Kent
Re: Problem Serializing schema grammar to disk
Posted by David Bertoni <db...@apache.org>.
Garner, Kenton (Mission Systems) wrote:
> I am trying to test the example provided by :
> http://www-128.ibm.com/developerworks/webservices/library/x-xsdxerc.html
> #code4
>
> I am new to XERCES-C, and I can not get past the second line of code (
> core dump ).
> I would appreciate any help I could get. I have an immediate need for
> this functionality and I would love to incorporate
> It in my project.
>
Take a look at the sample applications. It looks like you're not
initializing the library.
Dave