amouat / xsd-validator

Validates XML files against XML schema
Apache License 2.0
80 stars 25 forks source link

Validate.java use returncodes on error #13

Closed Xaratas closed 9 years ago

Xaratas commented 9 years ago

xsd-validator/src/xsdvalidator/validate.java

To use this nice wrapper in a pre-commit hook for git the errorcodes in the inner try need to have a non zero exit code:

            try {
                validator.validate(source);
                System.out.println(mXMLFileName + " validates.");
            }   
            catch (SAXParseException ex) {
                System.out.println(mXMLFileName + " fails to validate because: \n");
                System.out.println(ex.toString());
                System.out.println();
                System.exit(1);
            }   
            catch (SAXException ex) {
                System.out.println(mXMLFileName + " fails to validate because: \n");
                System.out.println(ex.getMessage());
                System.out.println();
                System.exit(1);
            }   
            catch (IOException io) {
                System.err.println("Error reading XML source: " + mXMLFileName);
                System.err.println(io.getMessage());
                System.exit(2);
            }   
        } catch (SAXException sch) {
            System.err.println("Error reading XML Schema: " + mXSDFileName);
            System.exit(2);
        }  
amouat commented 9 years ago

Yeah, that's a bug. I seem to have done it in one place and not others. I'll try to get to this soon, but I'm snowed under at the minute :(

amouat commented 9 years ago

BTW, what was your logic regarding which error code to use? 1 is failed validation and 2 is a file error?

Xaratas commented 9 years ago

So I thought. For my case i yust needed something >0.

Xaratas commented 9 years ago

One more the last catch should be:

        } catch (SAXException sch) {
            System.err.println("Error reading XML Schema: " + sch.getMessage());
            System.exit(2);
        }  
amouat commented 9 years ago

Finally merged this. Apologies for taking so long.

Xaratas commented 9 years ago

Oh, i saw you have not catched the error message change of my last comment. But thats the interesting part, why its not valid. ;)

amouat commented 9 years ago

Sorry, fixed now.