@Override public void setSchema(Schema schema) { spf.setSchema(schema); }
private static SAXParser newSAXParser(boolean namespaceAware, boolean validating, Schema schema1) throws ParserConfigurationException, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(validating); factory.setNamespaceAware(namespaceAware); factory.setSchema(schema1); return factory.newSAXParser(); }
/** * Return the SAXParserFactory we will use, creating one if necessary. */ public SAXParserFactory getFactory() { if (factory == null) { factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(namespaceAware); factory.setXIncludeAware(xincludeAware); factory.setValidating(validating); factory.setSchema(schema); } return (factory); }
/** * Factory method to create a SAXParser configured to validate according to a particular schema language and * optionally providing the schema sources to validate with. * * @param schemaLanguage the schema language used, e.g. XML Schema or RelaxNG (as per the String representation in javax.xml.XMLConstants) * @param namespaceAware will the parser be namespace aware * @param validating will the parser also validate against DTDs * @param schemas the schemas to validate against * @return the created SAXParser * @throws SAXException * @throws ParserConfigurationException * @since 1.8.7 */ public static SAXParser newSAXParser(String schemaLanguage, boolean namespaceAware, boolean validating, Source... schemas) throws SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(validating); factory.setNamespaceAware(namespaceAware); if (schemas.length != 0) { SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage); factory.setSchema(schemaFactory.newSchema(schemas)); } SAXParser saxParser = factory.newSAXParser(); if (schemas.length == 0) { saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", schemaLanguage); } return saxParser; }
/** * XMLReader instances from this class will be configured to validate using * the supplied Schema instance. * * @param fac * The SAXParserFactory to use for creating XMLReader instances. * @param schema * The Schema to use for validation. */ public AbstractReaderSchemaFactory(final SAXParserFactory fac, final Schema schema) { if (schema == null) { throw new NullPointerException("Cannot create a " + "SchemaXMLReaderFactory with a null schema"); } saxfac = fac; if (saxfac != null) { saxfac.setNamespaceAware(true); saxfac.setValidating(false); saxfac.setSchema(schema); } }
newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sfac.newSchema(); fac.setSchema(schema); val = true; } catch (SAXException se) {
@Override public void setSchema(Schema schema) { delegate.setSchema(schema); }
/** * Set the XML Schema to be used when parsing. * * @param schema The {@link Schema} instance to use. * @return This loader instance, useful to chain methods. */ public DigesterLoader setSchema( Schema schema ) { factory.setSchema( schema ); return this; }
/* Parsing with validation: */ SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setNamespaceAware(true); // add this line parserFactory.setSchema(schema);
private static SAXParser newSAXParser(boolean namespaceAware, boolean validating, Schema schema1) throws ParserConfigurationException, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(validating); factory.setNamespaceAware(namespaceAware); factory.setSchema(schema1); return factory.newSAXParser(); }
void createParser() throws SAXException { Schema schema = SchemaFactory.newSchema(new URL("http://www.mycomp.com/MyComp.dtd")); SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(true); factory.setSchema(schema);
private static SAXParser newSAXParser(boolean namespaceAware, boolean validating, Schema schema1) throws ParserConfigurationException, SAXException { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setValidating(validating); factory.setNamespaceAware(namespaceAware); factory.setSchema(schema1); return factory.newSAXParser(); }
String xml = "<root/>"; // XML as String File xsd = new File("schema.xsd"); // XSD as File SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(xsd); SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setSchema(schema); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); xr.parse(new InputSource(new StringReader(xml)));
@Override public void configureParser(XmlParser parser) { SAXParserFactory spf = parser.getSaxParserFactory(); spf.setValidating(false); // Not using a DTD if (schema!=null) { spf.setSchema(schema); } }
public void parseOrderXML() throws SAXException, IOException, ParserConfigurationException { File xmlDocument = Paths.get("src/main/resources/invalidOrder.xml").toFile(); File xmlSchema = Paths.get("src/main/resources/order.xsd").toFile(); DefaultHandler handler = new SaxParsingWithValidation04(); SAXParserFactory factory = SAXParserFactory.newInstance(); //Setting the Schema for validation SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(xmlSchema); factory.setSchema(schema); SAXParser saxParser = factory.newSAXParser(); saxParser.parse(xmlDocument, this); }
@Override public void configureParser(XmlParser parser) { SAXParserFactory spf = parser.getSaxParserFactory(); spf.setValidating(true); spf.setSchema(null); }
public void setValidating(boolean validate) { if (validate) { this.schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { this.schema = schemaFactory.newSchema(new StreamSource(getSchemaLocation())); } catch (org.xml.sax.SAXException e) { LOG.log(Level.SEVERE, "SCHEMA_FACTORY_EXCEPTION_MSG"); } this.parserFactory.setSchema(this.schema); } }
protected SAXParser saxParser() throws Exception { SAXParserFactory factory = FactorySupport.createSaxParserFactory(); factory.setNamespaceAware(namespaceAware); factory.setValidating(false); factory.setSchema(schema()); return factory.newSAXParser(); }
private static XMLReader createSaxReader(Schema schema) { final SAXParserFactory parserFactory = SAXParserFactory.newInstance(); parserFactory.setSchema(schema); parserFactory.setNamespaceAware(true); parserFactory.setXIncludeAware(true); try { return parserFactory.newSAXParser().getXMLReader(); } catch (ParserConfigurationException | SAXException e) { throw new MetafactureException(e); } }
@NonNull private static SAXParser getParser(int version) throws ParserConfigurationException, SAXException { Schema schema = DeviceSchema.getSchema(version); if (schema != null) { sParserFactory.setSchema(schema); } return sParserFactory.newSAXParser(); } }