Hi, all I'm trying to validate an XML document against an external schema. That is, the document itself does not contain a link to the schema; there is a local file containing the schema and I will validate every XML file against that.
However, the validation appears to be rejecting everything at this point. After stepping through the code it appears that the root element is rejected because its name is not found in the grammar hashtable. Thus, the loading of the grammar is not correctly populating the hashtable with element names. The grammar loader is able to find the schema correctly. I don't know the code well enough to say what it's doing when it traverses and saves it. The actually error message is "Unknown element 'AuditMessage'", which, if you look at the attached schema, is the valid root element. Now, I'm relatively new to both XML and Xerces, so I may be using the tool incorrectly (which is think is very likely because the grammar is a well-tested standard. I'm sure it's valid.) Below, I've included my code to create the parser and point it at the grammar. And, I've attached a file containing the validation schema. If anyone could shed some light on why the validation is always failing, I would appreciate it. Thank you. dan ----- Code to create the parser ----- XERCES_CPP_NAMESPACE::MemBufInputSource* inSource = 0; XERCES_CPP_NAMESPACE::XercesDOMParser *parser = 0; XERCES_CPP_NAMESPACE::DOMDocument *doc = 0; SatHL7ParseResult parseResult; // Can this throw? try { // Initialize the Parser. XERCES_CPP_NAMESPACE::XMLPlatformUtils::Initialize(); // Create our parser, then attach an error handler to the parser. // The parser will call back to methods of the ErrorHandler if it // discovers errors during the course of parsing the XML document. // parser = new XERCES_CPP_NAMESPACE::XercesDOMParser; parser->setValidationScheme(XERCES_CPP_NAMESPACE::XercesDOMParser::Val_Alway s); parser->setDoNamespaces(true); parser->setDoSchema(true); parser->setValidationSchemaFullChecking(true); parser->setCreateEntityReferenceNodes(false); char *schemaLocation = "..\\DATA\\JointStandardSchema_March2003.xsd"; Grammar *g = parser->loadGrammar(schemaLocation, Grammar::SchemaGrammarType); const char* bufferID = "ID"; //********** inSource = new XERCES_CPP_NAMESPACE::MemBufInputSource( (const XMLByte*)auditMessage, auditMessageSize, bufferID); // Set the error handler. SatXmlErrorHandler* errHandler = new SatXmlErrorHandler(); parser->setErrorHandler(errHandler); // Parse the XML stream, catching any XML exceptions that might propogate // out of it. // parser->parse(*inSource); doc = parser->getDocument(); ---- End of code --- ------------------------------------------------------------------------------- This message and any included attachments are from Siemens Medical Solutions USA, Inc. and are intended only for the addressee(s). The information contained herein may include trade secrets or privileged or otherwise confidential information. Unauthorized review, forwarding, printing, copying, distributing, or using such information is strictly prohibited and may be unlawful. If you received this message in error, or have reason to believe you are not authorized to receive it, please promptly delete this message and notify the sender by e-mail with a copy to [EMAIL PROTECTED] Thank you
JointStandardSchema_March2003.xsd
Description: Binary data
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]