Hi John

Maybe it's a subtle platform-specific thing (I'm testing on macosx), but the actual error is thrown because the scanner tries to read a directory entry (the current working directory) -- and not a real file. Whenever that value for the fExternalNoNamepaceSchemaLocation is a non-null pointer, the scanner appears to construct a file url, concatenating the current working directory with the file name (an empty string). So it ends up trying to open and read a directory instead of a file (e.g it tries to parse and read file:///user/jnapoli). I'll try on a different platform to see if I still see a problem.

Thanks,
Jerry

John Snelson wrote:
Hi Jerry,

That stack trace appears to be from a different problem (possibly a file not found?) - IGXMLScanner::scanTagStartNS doesn't appear in it anywhere.

I just tested XQilla using the simple-context-item.cpp sample which uses the IGXMLScanner, and it worked fine for me.

John

Jerry Napoli wrote:
Hi John,

It looks like I was having the issue with IGXMLScanner. Here is the stack trace:

#0  0x94d9a201 in __cxa_throw ()
#1 0x006c47ec in xercesc_2_8::XMLMacPosixFile::read at MacPosixFile.cpp:147 #2 0x006bf244 in xercesc_2_8::XMLPlatformUtils::readFileBuffer at MacOSPlatformUtils.cpp:268 #3 0x006091e8 in xercesc_2_8::BinFileInputStream::readBytes at BinFileInputStream.cpp:102 #4 0x0077e7c0 in xercesc_2_8::XMLReader::refreshRawBuffer at XMLReader.cpp:1699
#5  0x00781baa in xercesc_2_8::XMLReader::XMLReader at XMLReader.cpp:126
#6  0x00781cbf in xercesc_2_8::XMLReader::XMLReader at XMLReader.cpp:164
#7 0x006e807f in xercesc_2_8::ReaderMgr::createReader at ReaderMgr.cpp:439 #8 0x006b5282 in xercesc_2_8::IGXMLScanner::scanReset at IGXMLScanner2.cpp:1359 #9 0x006acaf1 in xercesc_2_8::IGXMLScanner::scanDocument at IGXMLScanner.cpp:195 #10 0x005f4811 in xercesc_2_8::AbstractDOMParser::parse at AbstractDOMParser.cpp:517 #11 0x006b3e05 in xercesc_2_8::IGXMLScanner::resolveSchemaGrammar at IGXMLScanner2.cpp:1858 #12 0x006a7c89 in xercesc_2_8::IGXMLScanner::scanStartTagNS at IGXMLScanner.cpp:2215 #13 0x006ac976 in xercesc_2_8::IGXMLScanner::scanContent at IGXMLScanner.cpp:896 #14 0x006acb50 in xercesc_2_8::IGXMLScanner::scanDocument at IGXMLScanner.cpp:214 #15 0x00d52ad9 in DocumentCacheImpl::parseDocument at src/schema/DocumentCacheImpl.cpp:268 #16 0x00d52822 in DocumentCacheImpl::loadDocument at src/schema/DocumentCacheImpl.cpp:253 #17 0x00d9b232 in FastXDMURIResolver::resolveDocument at src/fastxdm/FastXDMConfiguration.cpp:91 #18 0x00bf3b70 in XQDynamicContextImpl::resolveDocument at src/context/impl/XQDynamicContextImpl.cpp:337
#19 0x000023c1 in main at t_q2.cpp:17

It turns out the problem is in fact triggered by an empty string passed to XMLScanner::setExternalNoNamespaceSchemaLocation. It falls into this code in IGXMLScanner::scanTagStartNS (throwing at line 2215):

2209        if (isRoot && fDoSchema
2210 && (fExternalSchemaLocation || fExternalNoNamespaceSchemaLocation)) {
2211   2212            if (fExternalSchemaLocation)
2213                parseSchemaLocation(fExternalSchemaLocation);
2214            if (fExternalNoNamespaceSchemaLocation)
2215 resolveSchemaGrammar(fExternalNoNamespaceSchemaLocation, XMLUni::fgZeroLenString);
2216        }

The code in my main() is right out of the XQilla examples:

// Parse a document, and set it as the context item
Sequence seq = context->resolveDocument(X("foo.xml"), 0);


Thanks,
Jerry

John Snelson wrote:
It seems to me that the SGXMLScanner is at fault here, since XQilla works fine with the IGXMLScanner.

The problem seems to be caused because the IGXMLScanner uses a method called processSchemaLocation() to parse the schema location string, where as the SGXMLScanner uses XMLString::tokenizeString().

John

J Napoli wrote:
Hi,

While testing XQilla with Xerces-C 2.8.0 I was getting XML parse exceptions trying to run the basic examples. Looking into the code I noticed that XQilla by default passes an empty string (where val != NULL && XMLString::stringLen(val) == 0) to XMLScanner::setExternalSchemaLocation and setExternalNoNamespaceSchemaLocation. This seems to trick the scanner into thinking there is an external schema to parse. SGMLScanner::resolveSchemaGrammar then throws a parse exception because it tries to parse a URL constructed by concatenating the current working directory with the empty string.

Is this an XQilla or Xerces problem? Should Xerces ignore 0-length strings here?

Modifying XMLScanner::setExternalSchemaLocation to ignore 0-length strings seems to fix the problem (same issue with setExternalNoNamespaceSchemaLocation):

----

inline void XMLScanner::setExternalSchemaLocation(const XMLCh* const schemaLocation)
{
   if (fExternalSchemaLocation) {
       fMemoryManager->deallocate(fExternalSchemaLocation);
       fExternalSchemaLocation = NULL;
   }

   // Only set if we're passed a non-trivial string
   if (schemaLocation && XMLString::stringLen (schemaLocation))
fExternalSchemaLocation = XMLString::replicate(schemaLocation, fMemoryManager);
}

Thanks,
Jerry





Reply via email to