Example usage for javax.xml.parsers DocumentBuilderFactory newInstance

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

Introduction

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

Prototype

public static DocumentBuilderFactory newInstance() 

Source Link

Document

Obtain a new instance of a DocumentBuilderFactory .

Usage

From source file:Main.java

public static final DocumentBuilder getDocumentBuilder() throws Exception {
    return DocumentBuilderFactory.newInstance().newDocumentBuilder();
}

From source file:Main.java

static public Document newDocument() {
    Document document = null;//from  w w  w  .j a v  a2s. com
    DocumentBuilder builder = null;
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        builder = factory.newDocumentBuilder();
        document = builder.newDocument();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }

    return document;
}

From source file:Main.java

public static void test() {
    String xml = "C:\\Users\\is96092\\Desktop\\music\\test.xml";
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    try {/* w  w w.j  a  va2 s.co  m*/
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document dom = db.parse(xml);
        Element doc = dom.getDocumentElement();
        String role1 = "";
        role1 = getTextValue(role1, doc, "note");
        System.out.println("result : " + role1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static Document readXMLFile(String filename) throws IOException {

    DocumentBuilder builder;/*from   w w  w  . j a v a  2  s  .c o m*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        builder = factory.newDocumentBuilder();
        Document document = builder.parse(filename);
        return document;
    } catch (Exception e) {
        throw new IOException();
    }
}

From source file:Main.java

public static DocumentBuilderFactory getDocumentBuilderFactory() throws ParserConfigurationException {
    docFactory = DocumentBuilderFactory.newInstance();
    //this line of code not work properly
    //docFactory.setValidating(false);
    //this line of code evite to search the validation parameter just if you want read the xml coe withourt meta information
    docFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    return docFactory;
}

From source file:Main.java

public static DocumentBuilder newBuilder() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/*from  w ww  . jav  a2 s  .  c  o m*/
    dbf.setIgnoringElementContentWhitespace(true);
    return dbf.newDocumentBuilder();
}

From source file:Main.java

public static Element GetXmlDocFromStr(String xmlStr) {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;//  w w  w  . j a  va2  s.  c o m
    try {
        db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
        pce.printStackTrace();
    }
    Document doc = null;
    try {
        InputStream inputStream = new ByteArrayInputStream(xmlStr.getBytes());
        doc = db.parse(inputStream);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return (Element) doc.getDocumentElement();
}

From source file:Main.java

public static DocumentBuilder xmls() throws ParserConfigurationException {
    return DocumentBuilderFactory.newInstance().newDocumentBuilder();
}

From source file:Main.java

/**
 * Create a new DOM document/*from  ww  w .  j  av a2  s  .  co  m*/
 */
public static Document newDocument() throws IOException {
    try {
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        return builder.newDocument();
    } catch (ParserConfigurationException e) {
        throw new IOException(e.getMessage());
    }
}

From source file:Main.java

public static Document getXMLDocument(File file) {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = null;
    Document doc = null;/*  w ww.j a v a2  s  .c o  m*/
    try {
        docBuilder = dbf.newDocumentBuilder();
        doc = docBuilder.parse(file);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    return doc;
}