List of usage examples for org.jdom2.input SAXBuilder setProperty
public void setProperty(final String name, final Object value)
From source file:ca.nrc.cadc.dali.tables.votable.VOTableReader.java
License:Open Source License
/** * Create a XML parser using the schemaMap schemas for validation. * @param schemaMap Map of schema namespace to location. * @return XML parser./* ww w . jav a 2 s. c o m*/ */ protected SAXBuilder createBuilder(Map<String, String> schemaMap) { long start = System.currentTimeMillis(); boolean schemaVal = (schemaMap != null); String schemaResource; String space = " "; StringBuilder sbSchemaLocations = new StringBuilder(); if (schemaVal) { log.debug("schemaMap.size(): " + schemaMap.size()); for (String schemaNSKey : schemaMap.keySet()) { schemaResource = (String) schemaMap.get(schemaNSKey); sbSchemaLocations.append(schemaNSKey).append(space).append(schemaResource).append(space); } // enable xerces grammar caching System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", GRAMMAR_POOL); } XMLReaderSAX2Factory factory = new XMLReaderSAX2Factory(schemaVal, PARSER); SAXBuilder builder = new SAXBuilder(factory); if (schemaVal) { builder.setFeature("http://xml.org/sax/features/validation", true); builder.setFeature("http://apache.org/xml/features/validation/schema", true); if (schemaMap.size() > 0) { builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", sbSchemaLocations.toString()); } } long finish = System.currentTimeMillis(); log.debug("SAXBuilder in " + (finish - start) + "ms"); return builder; }
From source file:ca.nrc.cadc.uws.util.XmlUtil.java
License:Open Source License
public static SAXBuilder createBuilder(Map<String, String> schemaMap) { long start = System.currentTimeMillis(); boolean schemaVal = (schemaMap != null); String schemaResource;//from www .ja v a2 s . c o m String space = " "; StringBuilder sbSchemaLocations = new StringBuilder(); if (schemaVal) { log.debug("schemaMap.size(): " + schemaMap.size()); for (String schemaNSKey : schemaMap.keySet()) { schemaResource = (String) schemaMap.get(schemaNSKey); sbSchemaLocations.append(schemaNSKey).append(space).append(schemaResource).append(space); } // enable xerces grammar caching System.setProperty("org.apache.xerces.xni.parser.XMLParserConfiguration", GRAMMAR_POOL); } XMLReaderSAX2Factory factory = new XMLReaderSAX2Factory(schemaVal, PARSER); SAXBuilder builder = new SAXBuilder(factory); if (schemaVal) { builder.setFeature("http://xml.org/sax/features/validation", true); builder.setFeature("http://apache.org/xml/features/validation/schema", true); if (schemaMap.size() > 0) { builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", sbSchemaLocations.toString()); } } long finish = System.currentTimeMillis(); log.debug("SAXBuilder in " + (finish - start) + "ms"); return builder; }
From source file:Contabilidad.javaToXML.java
public boolean creaAndValidaXML(TFactDocMX comprobante, String nombre) { boolean response = false; generaRaiz(comprobante);/*from www . j a v a2s .c o m*/ XMLOutputter outputter = new XMLOutputter(); File folder = new File("nativos"); folder.mkdirs(); Format formato = Format.getPrettyFormat(); formato.setEncoding("UTF-8"); outputter.setFormat(formato); File archivoXml = new File(nombre); try { //Writer write = new FileWriter(archivoXml); FileOutputStream fop = new FileOutputStream(archivoXml); outputter.output(getXml(), fop); } catch (IOException e) { System.err.println("e1:" + e); return response; } //se instancia la clase que validara el XSD SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true); builder.setFeature("http://apache.org/xml/features/validation/schema", true); builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true); builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", COMPROBANTE_SCHEMA_XSD); builder.setValidation(true); //se imprime el documento si se logro cumplir con el XSD try { Document document = builder.build(archivoXml); //outputter.output(document, System.out); response = true; } catch (JDOMException e) { System.out.println("e2:"); error = e.toString(); e.printStackTrace(); } catch (IOException e) { System.out.println("e3"); error = e.toString(); e.printStackTrace(); } return response; }