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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Validate XML against XSD using the Xerces DOM Parser

843834Jul 15 2010 — edited Jul 15 2010
Hi!
I need to read XML with the Xerces DOM Parser and also validate it against prepared XSD. So far, I have this:
import java.io.IOException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import com.sun.org.apache.xerces.internal.parsers.DOMParser;


public class XMLParser {

  public XMLParser(String inputFile) {
    DOMParser parser = new DOMParser();
    try {
      parser.parse(inputFile);
      Document document = parser.getDocument();
    } catch (IOException e) {
      System.err.println (e);
    }
    catch (SAXException e) {
      e.printStackTrace();
    }
  }
}
Now I tried to find how to do the validation, but without success. I believe it should be done by setting
parser.setFeature();
but I don't now, what should be in the argument. Or am I wrong and there is different way? Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2010
Added on Jul 15 2010
1 comment
213 views