I am validating XML against a XSD. But my java validation error message is different from XMLSpy’s validation error message. Here XMLSpy is correct and java validation message is misleading. I am using following code to validate the XML:
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
SAXParser saxParser = factory.newSAXParser();
saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
saxParser.setProperty(JAXP_SCHEMA_SOURCE,new File("TXLife2.26.00.xsd"));
MySAXHandler dh = new MySAXHandler();
saxParser.parse(new File("test.xml"), dh);
Java validation message says:
cvc-complex-type.2.4.a: Invalid content was found starting with element ‘<element>’.
But XMLSpy says:
Element <element> is not allowed at this location under element <parent_element>
The error message you get depends on the validator you are using. Both are reporting the same error. If you want a Java XSD validator with better error messages, give Saxon a try: you may prefer it. But error reporting is an imprecise art: in designing error messages, an implementor is working with limited information about (a) what the user intended, and (b) how much the user understands about the technology.