Nov 19

You can specify a schema for validation when configuring the DocumentBuilderFactory that is used to parse the XML

static final String JAXP_SCHEMA_LANGUAGE =
    "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
static final String W3C_XML_SCHEMA =
    "http://www.w3.org/2001/XMLSchema";

DocumentBuilderFactory factory = 
   DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(url.openStream()); 

written by objects \\ tags: , , , , ,


Leave a Reply

You must be logged in to post a comment.