Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2012
    Rep Power

    Default Data Validation help

    Hello everyone,

    Can anyone please suggest me with some examples of how to validate data on the server side. I tried out the Javascript and looked at some regex methods. The regex methods actually use methods from the class Pattern. I cannot find examples that use the Validator class. I was told to read the Javadocs but I am not able to understand how those methods work.

    So I would appreciate if anyone could provide me with links to examples for validation at the server site.

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Tucson, AZ
    Rep Power

    Default Re: Data Validation help

    Javascript would be something you'd use on the client side.

    The Validator class is for validating XML against a Schema. Here's an excerpt from a program I'm working on right now. In this snippet, doc is a Document that was passed into the method. XMLInput is the name of the class in which this code appears.

    Java Code:
    StreamSource source =
    	new StreamSource(XMLInput.class.getResourceAsStream("/schema/Input.xsd"));
    SchemaFactory sf =
    Schema schema = sf.newSchema(source);
    Validator validator = schema.newValidator();
    // make it throw exceptions for all errors
    validator.setErrorHandler(new ErrorHandler() {
    	public void error(SAXParseException e) throws SAXException {
    		throw e;				
    	public void fatalError(SAXParseException e) throws SAXException {
    		throw e;					
    	public void warning(SAXParseException e) throws SAXException {
    		throw e;					
    validator.validate(new DOMSource(doc));
    That last line would throw a SAXException if the Document wasn't complete and correct according to the Schema.
    Last edited by kjkrum; 01-28-2012 at 04:30 PM.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. data type validation
    By cagipple in forum New To Java
    Replies: 2
    Last Post: 12-14-2011, 07:57 AM
  2. XML Validation
    By sehudson in forum XML
    Replies: 5
    Last Post: 03-21-2011, 12:38 PM
  3. Replies: 4
    Last Post: 01-29-2011, 11:18 PM
  4. Replies: 0
    Last Post: 09-01-2008, 11:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts