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 void main(String[] args) throws Exception {
    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder domBuilder = domFactory.newDocumentBuilder();
    domBuilder.parse(args[0]);//from   w  ww.j  a v  a  2 s . co  m
    System.out.println("'" + args[0] + "' is well-formed.");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setIgnoringComments(true);//from  www  . j  av a2s  .co m

    Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setCoalescing(true);/*from www. j  a  va2  s. c  om*/

    Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));

    // doc will not contain any CDATA nodes
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setIgnoringComments(true);/* ww  w  . j a v a  2 s .  c  o  m*/

    Document doc = factory.newDocumentBuilder().parse(new File("infilename.xml"));
    // doc will not contain any Comment nodes
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//from  w  w  w  .  j av a2s. com

    // Prevent expansion of entity references
    factory.setExpandEntityReferences(false);

    // Create the builder and parse the file
    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);// ww w.  ja  v a2 s.  c  o  m
    factory.setExpandEntityReferences(false);
    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");

    String attrValue = element.getAttribute("value");
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//from   ww w  .j a  v a2  s  .c  om

    factory.setExpandEntityReferences(false);

    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Comment comment = doc.createComment("invalid -- comment");
    boolean validComment = comment.getNodeValue().indexOf("--") < 0;
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);//w  w  w  .  jav  a  2  s.  co m
    factory.setExpandEntityReferences(false);
    Document doc = factory.newDocumentBuilder().parse(new File("filename"));
    Element element = doc.getElementById("key1");

    element.setAttribute("newAttrName", "attrValue");
    element.setAttribute("newAttrName", "<>&\"'");
    element.removeAttribute("value");
    boolean has = element.hasAttribute("value"); // true
    String attrValue = element.getAttribute("value"); // mydefault
}

From source file:TryDOM.java

public static void main(String args[]) {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    try {//w  ww.  j  ava  2s.  co m
        builder = builderFactory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        System.exit(1);
    }
    System.out.println("Builder Factory = " + builderFactory + "\nBuilder = " + builder);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;/* w w w  . j ava 2  s. co  m*/
    db = dbf.newDocumentBuilder();
    Document doc = db.parse(new File("games.xml"));
}