Skip to main content

validator not working on schema

1 reply [Last post]
scphantm
Offline
Joined: 2008-07-16

here is the relevant part of my xml

0
0
No Error
2008-07-16T15:12:30.531Z

abc
def
.
.
.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
scphantm
Offline
Joined: 2008-07-16

sorry, hit the wrong button.
now here is my schema im trying to validate against:






The reponse schema for the GetChildrenVouchers transaction













and here is the response section of the commontypes.xsd








now when i load the main doc xsd, it loads fine but when i try to validate i get this exception

org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'com:Response'. One of '{Response, TrackingType, VoidOption, CurrentTrackingPeriodBeginDate, MenuOptions, ProviderMsgs, CardHolders}' is expected.
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator$XSIErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.reportSchemaError(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.jaxp.validation.StreamValidatorHelper.validate(Unknown Source)
at org.apache.xerces.jaxp.validation.ValidatorImpl.validate(Unknown Source)
at javax.xml.validation.Validator.validate(Validator.java:82)
at com.jpmc.paycare.junit.util.SchemaValidator.isValid(SchemaValidator.java:69)
at com.jpmc.paycare.junit.getchildrenvouchers.XMLMessagingTest.first(XMLMessagingTest.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at junit.framework.JUnit4TestAdapter.run(JUnit4TestAdapter.java:36)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:421)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.launch(JUnitTestRunner.java:912)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:766)

the crazy thing is if i take this exact same xml, add the schema location to it and plug it into XMLSpy, it validates perfectly. now whats wrong here?

here is my validation code
Handler handler = new Handler();

SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
//schemaFactory.setErrorHandler(handler);
// create a grammar object.
Schema schemaGrammar = schemaFactory.newSchema(new File(file));

System.out.println("Created Grammar object for schema : " + file);

Resolver resolver = new Resolver();
// create a validator to validate against grammar sch.
Validator schemaValidator = schemaGrammar.newValidator();
schemaValidator.setResourceResolver(resolver);
//schemaValidator.setErrorHandler(handler);

System.out.println("Validating " + input + " against grammar " + file);
// validate xml instance against the grammar.

schemaValidator.validate(new StreamSource(new StringReader(input)));