Lisa Davis wrote:
  Hi,
  I am having problems converting from the DOM parser to the SAX2 parser.
  I have code that will parse an xml file, using a schema, without error for 
DOM.
  When I try to parse the same xml file, using the same scheme with SAX2, the 
parser reports errors.
  Here is the code to configure the DOM and SAX2 parsers. What am I doing wrong 
for SAX2?
  FYI, the my_DefaultHandler is currently an empty wrapper around the 
DefaultHandler class.
  --DOM
  parser->setCreateEntityReferenceNodes(false);
  parser->setExpandEntityReferences(true);
  if (!schemaFile.empty()) {
  parser->setDoNamespaces(true);
  parser->setDoSchema(true);
  parser->setValidationScheme(XercesDOMParser::Val_Always);
  parser->setIncludeIgnorableWhitespace(false);
  parser->setCreateCommentNodes(false);
  parser->setExternalNoNamespaceSchemaLocation(schemaFile.c_str());
  }
  --SAX2
  if (!schemaFile.empty()) {
  parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
  parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);
  parser->setFeature(XMLUni::fgXercesSchema, true);
  parser->setFeature(XMLUni::fgXercesSchemaFullChecking, false);
parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, reinterpret_cast<void*>(const_cast<char*>(schemaFile.c_str())));
  }

The SAX2 parser expects this property to be set using a UTF-16 string. AbstractDOMParser happens to have a convenience function that accepts a const char* and does the transcoding from the local code page to UTF-16 for you.

You will need to use of the XMLString::transcode() functions to transcode the file name to UTF-16 before you set the property.

Dave

Reply via email to