Hey Vitaly, many thanks for your help. Interesting. Ok I'll try this sample out.
Thanks. On 5 April 2017 at 10:36, Vitaly Prapirny <m...@mebius.net> wrote: > Hi, > > You can try to validate your files with some of the Xerces-C++ sample > applications (e.g. DOMCount) and see what is the difference. Maybe your > XMLValidator_ParserErrorHandler didn't handle errors properly. > > Good luck! > Vitaly > > Bodi Ngwala wrote: > >> Hi >> >> I am testing XML vs XSD validation using the Xerces-C++. >> I have an XML which contains an invalid tag <OffersLookupService1> and my >> XSD contains the valid <OffersLookupService>, when I run the following >> code, it validates my XML without error. I'm rather expecting to fail. >> >> XERCES_CPP_NAMESPACE::XercesDOMParser dom_parser; >> XMLValidator_ParserErrorHandler error_handler; >> dom_parser.setErrorHandler(&error_handler); >> dom_parser.setValidationScheme(XERCES_CPP_NAMESPACE::XercesD >> OMParser::Val_Auto); >> dom_parser.setDoNamespaces(true); >> dom_parser.setDoSchema(true); >> dom_parser.setValidationConstraintFatal(true); >> dom_parser.useCachedGrammarInParse(false); >> dom_parser.setExitOnFirstFatalError(true); >> dom_parser.setValidationSchemaFullChecking(true); >> // dom_parser.setExternalNoNamespaceSchemaLocation(my_schema_ >> source.c_str()); >> >> XERCES_CPP_NAMESPACE::MemBufInputSource in_memory_schema_buffer((XMLBy >> te*) >> my_schema_source.c_str(), my_schema_source.size(), "my schema buffer"); >> if (dom_parser.loadGrammar(in_memory_schema_buffer, >> XERCES_CPP_NAMESPACE::Grammar::SchemaGrammarType) == NULL) // ,true to >> cache >> { >> request_details->setError(SchemaError_DOMParserCouldNotLoadSchema, >> "Failed >> to load schema"); >> return false; >> } >> try >> { >> >> XERCES_CPP_NAMESPACE::MemBufInputSource in_memory_xml_buffer((XMLByte*) >> my_xml_source.c_str(), my_xml_source.size(), "my xml buffer"); >> dom_parser.parse(in_memory_xml_buffer); >> if (dom_parser.getErrorCount() == 0) >> { >> request_details->setError(Validation_OK, ""); >> <------------------------------------- >> ALWAYS SUCCEEDS ? Why? >> } >> else >> { >> request_details->setError(XMLError_FileDoesNotConformToSchema, "Schema >> validation failed"); >> } >> .... >> >> When I use the online validator (http://www.utilities-online.i >> nfo/xsdvalidation/#.WMqyD_mLRaQ) it fails as expected with error: >> >> "Not valid. >> Error - Line 6, 24: org.xml.sax.SAXParseException; lineNumber: 6; >> columnNumber: 24; cvc-complex-type.2.4.a: Invalid content was found >> starting with element 'OffersLookupService1'. One of >> '{OffersLookupService}' is expected." >> >> >> >> my_xml_source in abovementioned code contains this XML: >> <?xml version="1.0" encoding="UTF-8"?> >> <Get> >> <OffersLookupService1> >> <Transaction> >> (... simplified for clarity .... ) >> </Transaction> >> </OffersLookupService1> >> </Get> >> >> >> my_schema_source in abovementioned code contains this XSD: >> <?xml version='1.0' encoding='utf-8'?> >> <xs:schema xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' >> attributeFormDefault='unqualified' elementFormDefault='unqualified' >> xmlns:xs='http://www.w3.org/2001/XMLSchema'> >> <xs:element name='Get'> >> <xs:complexType> >> <xs:sequence> >> <xs:element name='OffersLookupService'> >> <xs:complexType> >> <xs:sequence> >> <xs:element name='Transaction'> >> <xs:complexType> >> <xs:sequence> >> <xs:any minOccurs='1' namespace='http://www.nrf-arts >> .org/IXRetail/namespace/' >> processContents='lax' /> >> </xs:sequence> >> </xs:complexType> >> </xs:element> >> </xs:sequence> >> </xs:complexType> >> </xs:element> >> </xs:sequence> >> <xs:attribute name='version' type='xs:string' use='required' /> >> </xs:complexType> >> </xs:element> >> </xs:schema> >> >> >> Could someone please explain why is Xerces not failing in this case? Is >> there misconfiguration in my code? >> >> Many thanks. >> >> >