Example usage for org.jdom2.input SAXBuilder SAXBuilder

List of usage examples for org.jdom2.input SAXBuilder SAXBuilder

Introduction

In this page you can find the example usage for org.jdom2.input SAXBuilder SAXBuilder.

Prototype

@Deprecated
public SAXBuilder(final String saxDriverClass, final boolean validate) 

Source Link

Document

Creates a new SAXBuilder using the specified SAX2.0 parser source.

Usage

From source file:ca.nrc.cadc.uws.util.XmlUtil.java

License:Open Source License

/**
 * Build a XML Document from string, without schema validation
 * /*w w  w  .  ja  v  a  2 s  .  c o m*/
 * @param xml
 * @return
 * @throws IOException 
 * @throws JDOMException 
 */
public static Document buildDocument(String xml) throws JDOMException, IOException {
    SAXBuilder parser = new SAXBuilder(PARSER, false);
    return parser.build(new StringReader(xml));
}

From source file:Contabilidad.javaToXML.java

public boolean creaAndValidaXML(TFactDocMX comprobante, String nombre) {
    boolean response = false;
    generaRaiz(comprobante);//from   www.jav a  2  s .  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;
}