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 Florent Philippe <ph...@yahoo.fr> on 2006/09/07 00:20:33 UTC
MemBufInputSource ? how do you do a simple memory parsing ..?
Hello,
I try to figure out how to parse memory like a tree,I already parse with SAX and a mem buffer inputsource and it works progressively or in one shot, but how do i get the results ?
The thing is I added some enumeval exemple parts, hoping that I would have an output or something but it reach the error :Non schema document, no output available
I don't want to use DTD, I only want to be able to parse the elements of the xml string buffer(comes from network)
i thought 1st parsefirst and parsenext would do the trick but how is it possible to get the values of the xml tags and attributes ?
here is the code :
SAXParser* parser = new SAXParser;
parser->setValidationScheme(SAXParser::Val_Always);
parser->setDoNamespaces(true);
parser->setDoSchema(true);
//parser->setValidationSchemaFullChecking(false); ----- don't work if i uncomment it
MemParseHandlers handler;
parser->setDocumentHandler(&handler);
parser->setErrorHandler(&handler);
MemBufInputSource* memBufIS = new MemBufInputSource((const XMLByte*)XMLBuffer, size, gMemBufId, false);
unsigned long duration;
int errorCount = 0;
try
{
//////////////////////////////// full parse
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
parser->parse(*memBufIS);
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
duration = endMillis - startMillis;
errorCount = parser->getErrorCount();
// Create a progressive scan token
/* XMLPScanToken token;
const unsigned long startMillis = XMLPlatformUtils::getCurrentMillis();
if (!parser->parseFirst(*memBufIS, token))
{
LogPrint(MT_ERROR,"error reading XML");
XMLPlatformUtils::Terminate();
return false;
}
bool gotMore = true;
while (gotMore && !parser->getErrorCount())
gotMore = parser->parseNext(token);
const unsigned long endMillis = XMLPlatformUtils::getCurrentMillis();
duration = endMillis - startMillis;
errorCount = parser->getErrorCount();
parser->parseReset(token);*/
}
catch (const OutOfMemoryException&)
{
LogPrint(MT_ERROR,"OutOfMemoryException");
XMLPlatformUtils::Terminate();
return false;
}
catch (const XMLException& e)
{
LogPrint(MT_ERROR,"Error during parsing memory stream:Exception message is: %s",StrX(e.getMessage()));
XMLPlatformUtils::Terminate();
return false;
}
if (!parser->getValidator().handlesSchema())
{
LogPrint(MT_ERROR," Non schema document, no output available");
return false;
}
Grammar* rootGrammar = parser->getRootGrammar();
if (!rootGrammar || rootGrammar->getGrammarType() != Grammar::SchemaGrammarType)
{
LogPrint(MT_ERROR," Non schema grammar, no output available" );
---------------------error comes here ----------------------------------------------
return false;
}
SchemaGrammar* grammar = (SchemaGrammar*) rootGrammar;
RefHash3KeysIdPoolEnumerator<SchemaElementDecl> elemEnum = grammar->getElemEnumerator();
if (!elemEnum.hasMoreElements())
{
LogPrint(MT_ERROR,"The validator has no elements to display");
return false;
}
//DTDValidator* valToUse = new DTDValidator;
// Print out the stats that we collected and time taken.
if (!errorCount)
{
while(elemEnum.hasMoreElements())
{
const SchemaElementDecl& curElem = elemEnum.nextElement();
// Name
LogPrint(MT_INFO,"Name:\t\t\t%s",StrX(curElem.getFullName()));
// Model Type
LogPrint(MT_INFO,"Model Type:\t\t",StrX(curElem.getFullName()));
switch( curElem.getModelType() )
{
case SchemaElementDecl::Empty: LogPrint(MT_INFO,"Empty"); break;
case SchemaElementDecl::Any: LogPrint(MT_INFO,"Any"); break;
case SchemaElementDecl::Mixed_Simple: LogPrint(MT_INFO,"Mixed_Simple"); break;
case SchemaElementDecl::Mixed_Complex: LogPrint(MT_INFO,"Mixed_Complex"); break;
...
...
please help me, it seems so easy to do but I been looking for two days already
thx alot
good night folks