Hi Robert,
if by "pointers are invalid" you mean that you cannot print them using printf, it could be that they are XMLCh* and must be transcoded if you want to "see" their values.

Alberto

Il 15/04/2011 11:13, Robert Wermuth ha scritto:
Hi Alberto,
thanks a lot, now it works.
But I have an another point. When I compile my wrong code as release build,
but with optimation deactivated (compiler option /Od), the program don't
crashes. But the pointers in the "XMLResourceIdentifier
*resourceIdentifier"-parameter of my MyEntityResolver are also invalid.
I don't know how important this information is for you.

Greetings
Robert

2011/4/15 Alberto Massari<alberto.mass...@progress.com>

Hi Robert,
you are creating an XMLEntityResolver, but using the setEntityResolver API
that expects an EntityResolver interface; infact, you had to add a cast to
force the compiler in doing this illegal thing.
You should instead use the setXMLEntityResolver API, that accepts the
correct base interface. However, it's not available in the SAX2XMLReader
interface, and you will have to cast it down to the implementation class

    ((SAX2XMLReaderImpl*)pParser)->setXMLEntityResolver(&XmlEntityResolver);

Alberto

Il 15/04/2011 10:33, Robert Wermuth ha scritto:

Hi Alberto,
at first thanks for your fast answer. I am using stack objects, but I
starts
the parsing in an child stackframe, so that the stackobjects should be
valid
at parse-time. The program runs in debug build well, but in the release
build it crashes. I found out that it crashes at XMLString::replicate()
(called by RegxParser::parse()) at the memcpy()-function. The program
don't
crashes if I remove my own entity resolver.

Here is some code of my program for you:

Here is my entity resolver:

class MyEntityResolver : public XMLEntityResolver
{
public:
virtual ~MyEntityResolver()
{

}


MyEntityResolver()
{

}

virtual InputSource *resolveEntity(XMLResourceIdentifier
*resourceIdentifier)
{
//this prozedure get fired one time, but all the pointers are invalid (I
made them public for reading them)
printf("BaseURI: 0x%08X\nLocator: 0x%08X\nNameSpace: 0x%08X\nPublicId:
0x%08X\nResourceIdentifierType: 0x%08X\n"
"SystemId: 0x%08X"
, (UINT) resourceIdentifier->fBaseURI, (UINT)
resourceIdentifier->fLocator,
(UINT) resourceIdentifier->fNameSpace, (UINT)
resourceIdentifier->fPublicId,
(UINT) resourceIdentifier->fResourceIdentifierType, (UINT)
resourceIdentifier->fSystemId);

return g_pMemBufSourceForDTD;
}
};


And here is the code for parsing the XML-file:

SAX2XMLReader* pParser = XMLReaderFactory::createXMLReader();

XMLPScanToken Token;
MyDocumentHandler XmlHandler;

MemoryManagerImpl MemManager;
void * pDestXMLData;
Grammar * pGrammar;

pDestXMLData = MemManager.allocate(p_nSize);
memcpy(pDestXMLData, p_pXMLData, p_nSize);

MemBufInputSource MemBufSource(
(const XMLByte *) pDestXMLData,
p_nSize,
"Fake sytem ID",
FALSE,
&MemManager);

pParser->setContentHandler(&XmlHandler);

MyErrorHandler XmlErrorHandler;
pParser->setErrorHandler(&XmlErrorHandler);


MyEntityResolver XmlEntityResolver;
pParser->setEntityResolver((EntityResolver *const)&XmlEntityResolver);

pGrammar = pParser->loadGrammar(
*g_pMemBufSourceForDTD,
Grammar::DTDGrammarType,
TRUE);

pParser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, TRUE);
pParser->setFeature(XMLUni::fgXercesSchemaFullChecking, TRUE);
pParser->setFeature(XMLUni::fgSAX2CoreValidation, TRUE);
pParser->setFeature(XMLUni::fgXercesSkipDTDValidation, FALSE);
pParser->setFeature(XMLUni::fgXercesLoadExternalDTD, TRUE);
pParser->setFeature(XMLUni::fgXercesDynamic, TRUE);

try
{
if(!pParser->parseFirst(MemBufSource, Token))    //Here is the crash!
{
goto ParseError;
}

while(pParser->parseNext(Token))
{
if(g_bParseError == TRUE)
{
MemManager.deallocate(pDestXMLData);
delete pParser;
return FALSE;
}
}
}

Is that all you need?

Greetings
Robert

2011/4/14 Alberto Massari<alberto.mass...@progress.com>

Hi Robert,
it's hard to tell what's wrong without seeing your code. I would guess you
are allocating an object on the stack that is destroyed before the parsing
take place...
Could you share the code you are using?

Alberto

Il 14/04/2011 17:56, Robert Wermuth ha scritto:

Hello,
I am using xerces 3.1.1 with the SAX2XMLReader. I use
pParser->setEntityResolver() to install my own entity resolver. I compile
my
project with Visual Studio c++ 9.1 (using the static xerces libs). But in
the Release build my program crashes on pParser->parseFirst() when I set
my
entity resolver.I tried to compile the example code shown there:
http://xerces.apache.org/xerces-c/apiDocs-3/classXMLEntityResolver.html.
But
I get a compiler error (XMLResourceIdentifier::SystemId is not defined.).
Is
there an error in the lib?

Greetings
Robert


  .

.


Reply via email to