Neil,
Thanks for the reply.
Your curiosity is well-founded in my case c).
I re-tested this and I DO NOT get validation errors (i.e. parse is
successful) with:
- use cached grammars == true, and
- PSVIHandler NOT registered.
I have tried calling lockPool after the ::loadGrammar, but before the
parse and it doesn't seem to help.
Should the basic strategy below work with the
xerces/samples/data/personal.xsd and
xerces/samples/data/personal-schema.xml files?
I've tried this and it succeeds and fails in the same way as my app's
XSD and XML file combination:
- Parses without errors with useCachedGrammar = true and PSVIHandler
OFF.
- Gets proper PSVI info with useCachedGrammar = false and PSVIHandler
ON.
- No PSVI info and crash in parser with useCachedGrammar = true and
PSVIHandler ON.
Again, my application requires that both PSVI and useCachedGrammar be
ON/true.
Is it possible for someone to try the following code with the
personal.xsd and personal-schema.xml sample files?
-----
XMLGrammarPool* pGrammarPool = new
XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
SAX2XMLReaderImpl* pReader = new
SAX2XMLReaderImpl(XMLPlatformUtils::fgMemoryManager, pGrammarPool);
// CmjTestingErrorHandler derives from ErrorHandler and PSVIHandler and
has empty implementations of
// warning, error, fatalError, handlePartialElementPSVI,
handleElementPSVI and handleAttributesPSVI.
// handlePartialElementPSVI and handleElementPSVI have one line
implementations that look like:
// XSTypeDefinition* pTypeInfo = elementInfo->getTypeDefinition();
// in order to check the validity of the TypeInfo.
CmjTestingErrorHandler* pErrorHandler = new CmjTestingErrorHandler();
pReader->setErrorHandler(pErrorHandler);
pReader->setPSVIHandler(pErrorHandler);
pReader->setProperty(XMLUni::fgXercesScannerName, (void
*)XMLUni::fgSGXMLScanner);
pReader->setFeature(XMLUni::fgSAX2CoreValidation, true);
pReader->setFeature(XMLUni::fgXercesDynamic, true);
pReader->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
pReader->setFeature(XMLUni::fgXercesSchema, true);
pReader->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
pReader->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
// load the XSD grammar
Grammar* pGrammar = pReader->loadGrammar(<path to
personal.xsd>Grammar::SchemaGrammarType, true);
ASSERT(pGrammar != NULL);
// NOW tell the parser we want to use what we've cached...
pReader->setFeature(XMLUni::fgXercesUseCachedGrammarInParse, false);
pGrammarPool->lockPool();
// parse the XML file
pReader->parse(TestXerces::GetMapPath(<path to personal.xml>);
delete pReader;
delete pGrammarPool;
-----
Still hopeful...thanks again.
- j e f f
-----Original Message-----
From: Neil Graham [mailto:[EMAIL PROTECTED]
Sent: Tuesday, May 24, 2005 10:30 AM
To: [email protected]
Subject: Re: PSVIHandler and UseCachedGrammarInParse at the same time?
Hi Jeff,
Not sure why this isn't working for you. I am a little curious about
why you're getting validation errors in case c); is this something you
expect?
i.e., are you using an invalid instance as your test case?
Have you tried calling lockPool() on your XMLGrammarPool implementation
before initiating the parse? If you're using the default
implementation, this will make sure that the XSModel is fluffed up.
Cheers,
Neil
Neil Graham
Manager, XML Parser Development
IBM Toronto Lab
Phone: 905-413-3519, T/L 969-3519
E-mail: [EMAIL PROTECTED]
"Jeff Lynch" <[EMAIL PROTECTED]>
05/23/2005 11:41 AM
Please respond to
c-dev
To
<[email protected]>
cc
Subject
PSVIHandler and UseCachedGrammarInParse at the same time?
Hi All,
I am curious if anyone has used both a PSVIHandler and
fgXercesUseCachedGrammarInParse set to true and had satisfactory
results? I figured that I would post a question to the list and then
dive into debugging inside of xerces to see if I can figure out where it
seemingly goes astray. Any help, suggested fixes or workarounds are
appreciated.
-----
The summary goes something like this:
1) Load and cache an XSD file from a resource into my own XSGrammarPool
using ::loadGrammar.
2) Allocate a SAX2ReaderImpl using that grammar pool.
3) Set the PSVIHandler callback.
4) Parse an XML file (also from a resource).
- I get reasonable data in the handlePartialElementPSVI and
handleElementPSVI callbacks with fgXercesUseCachedGrammarInParse set to
false (but this fails, since the version of the schema on the web is out
of date). By reasonable data, I mean that I can call
elementInfo->getTypeDefinition() in the callback and get Non-NULL data.
5) If I set fgXercesUseCachedGrammarInParse to true, I get NULL from
calls to elementInfo->getTypeDefinition(), and furthermore, the parser
crashes in SGXMLScanner::buildAttList (or IGXMLScanner::buildAttList, as
I've tried both scanners), below the comment "// now fill in the
PSVIAttributes entry for this attribute:" because the validatingType
local variable is NULL (and the parser calls ::getVariety() on that null
pointer.
-----
I need to have both of these things working at the same time. I am first
going to try to figure out why xerces cannot obtain the typeInfo
successfully (see #5).
-----
Other things I've tested:
- NO PSVIHandler set, but WITH an error handler set and
fgXercesUseCachedGrammarInParse set to true, the parse runs without
errors.
- I have used both the 2.6 code as well as the head revision from the
now-read-only CVS archive without any change in the results.
- I have tested both 2.6 and CVS on both Win32 (WinXP) and Mac OS X
(10.4/Tiger).
- I have tried using both the SGXMLScanner and IGXMLScanner during the
parse.
-----
Code details are here:
m_pGrammarPool = new
XMLGrammarPoolImpl(XMLPlatformUtils::fgMemoryManager);
m_pSaxReader = new
SAX2XMLReaderImpl(XMLPlatformUtils::fgMemoryManager, m_pGrammarPool);
pGrammar = m_pSaxReader->loadGrammar(anInputSource,
Grammar::SchemaGrammarType, true);
m_pParser->setFeature(XMLUni::fgSAX2CoreValidation, true);
m_pParser->setFeature(XMLUni::fgXercesDynamic, true);
m_pParser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
m_pParser->setFeature(XMLUni::fgXercesSchema, true);
m_pParser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
m_pParser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
m_pParser->setFeature(XMLUni::fgXercesUseCachedGrammarInParse,
true); // #1
m_pParser->setProperty(XMLUni::fgXercesScannerName,
(void*)XMLUni::fgSGXMLScanner);
m_pParser->setErrorHandler(m_pXercesSaxHandler);
m_pParser->setPSVIHandler(m_pXercesSaxHandler); // #2
Three scenarios:
A) With #1 set to true and #2 in place, we get null TypeInfo in the PSVI
element callbacks and a parser crash.
B) With #1 set to false and #2 in place, we get correct TypeInfo in the
PSVI element callbacks, but validation failure because it doesn't look
for the cached grammar.
C) With #1 set to true and #2 commented out (i.e. no PSVIHandler set),
the validation fails (but clearly we don't get any PSVI info (which I
need for my application)).
-----
Thanks again for any input or direction (off to do some debugging)...
- j e f f
---------------
jeffrey.w.lynch
Mindjet, Inc.
www.mindjet.com
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]