Example usage for javax.xml.parsers DocumentBuilderFactory setAttribute

List of usage examples for javax.xml.parsers DocumentBuilderFactory setAttribute

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilderFactory setAttribute.

Prototype

public abstract void setAttribute(String name, Object value) throws IllegalArgumentException;

Source Link

Document

Allows the user to set specific attributes on the underlying implementation.

Usage

From source file:psidev.psi.mi.filemakers.xmlFlattener.structure.XsdTreeStructImpl.java

/**
 * Open a frame to choose an XML document and load it.
 * /*  w w w.ja v a2 s.  c o m*/
 */
public void loadDocument(URL url)
        throws FileNotFoundException, NullPointerException, MalformedURLException, IOException, SAXException {
    maxCounts = new HashMap<XsdNode, Integer>();

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(validateDocument);

    factory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA);
    factory.setAttribute(SCHEMA_SOURCE, schemaURL);
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        log.debug("XML document url: " + url.toString());
        builder.setErrorHandler(xmlErrorHandler);
        document = builder.parse(url.toString());
        this.documentURL = url;

        /* get all references */
        log.debug("get keys/keyRefs");
        buidKeyMaps();
        for (String refer : refType2referedType.keySet()) {
            String refered = refType2referedType.get(refer);
            log.debug("found reftype: " + refer + " refers " + refered);
        }
        log.debug("done");

        log.debug("document parsed ... get elements");
        setLineNode(lineXsdNode);

        Utils.lastVisitedDirectory = url.getPath();
        Utils.lastVisitedDocumentDirectory = url.getPath();
    } catch (ParserConfigurationException e) {
        /** TODO: manage excepton */
    }
}

From source file:psidev.psi.mi.filemakers.xmlMaker.structure.XsdTreeStructImpl.java

public void validateXml(File xmlFile, Writer log) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);//from  w  ww  . j  av a2  s .c om
    factory.setValidating(true);

    factory.setAttribute(SCHEMA_LANGUAGE, XML_SCHEMA);
    factory.setAttribute(SCHEMA_SOURCE, schemaURL);
    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        builder.setErrorHandler(xmlErrorHandler);
        /**
         * TODO: check if it is necessary 
         */
        builder.parse(xmlFile);
    } catch (ParserConfigurationException e) {
        /** TODO: manage exception */
    } catch (SAXException e2) {
        /** TODO: manage exception */
    } catch (OutOfMemoryError ooo) {
        try {
            log.write("ERROR: not enougth memory to perform XML validation");
        } catch (IOException e3) {
            /** TODO: manage exception */
        }
        getMessageManager().sendMessage("ERROR: not enougth memory to perform XML validation",
                MessageManagerInt.errorMessage);
    } catch (IOException e3) {
        /** TODO: manage exception */
    }

}