Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

XML Validation Errors?

843834Jan 26 2004 — edited Jan 27 2004
Hi all,

I am parsing an XML file passed in at the cmd line and using this method to return a boolean if depending if the validation was ok....I have successfully validated against the particular file that I am passing in against a valid XSD and it works fine. But when I do this here it gets caught as an error straight away.

Can anyone see any obvious mistakes with this code or have any suggestions?
public boolean validateXML() {

        try {
        boolean validate = true;
        parser.setFeature("http://xml.org/sax/features/validation", validate);

        //CustomerErrorHandler extends SAX ErrorHandler
        CustomErrorHandler handler = new CustomErrorHandler();

        //Install/Enable the parser to handle parsing errors
        parser.setErrorHandler(handler);
        parser.parse(args[0]);

        System.out.println("YOU ARE IN THE XMLVALIDATOR CODE NOW!!!!");

        validXML = true;

        }

        catch (Exception ex) {
            System.out.println("An error has been caught, following validation");
            validXML = false;
        }

        return validXML;
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 24 2004
Added on Jan 26 2004
6 comments
460 views