Example usage for javax.xml.parsers DocumentBuilderFactory setNamespaceAware

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

Introduction

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

Prototype


public void setNamespaceAware(boolean awareness) 

Source Link

Document

Specifies that the parser produced by this code will provide support for XML namespaces.

Usage

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);/*from   w ww.j  a va  2 s  . c  o  m*/
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            addCDATA(doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);//w w  w .  jav a2  s  . c  om
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            importName(doc, doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMCopy.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);//  w ww .  j  av a  2s  .  co  m
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);//from w  ww.  j a v a  2 s.c  om
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            modifyingTextbyCuttingandPasting(doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:com.cladonia.security.signature.SignatureVerifier.java

public static void main(String[] args) throws Exception {
    org.apache.commons.logging.Log log = org.apache.commons.logging.LogFactory
            .getLog(SignatureGenerator.class.getName());

    log.info("**** Testing Signature Verification *****");

    javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);

    File f = new File("c:\\temp\\sigout.xml");
    javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
    org.w3c.dom.Document doc = db.parse(new java.io.FileInputStream(f));

    SignatureVerifier verifier = new SignatureVerifier(doc, XngrURLUtilities.getURLFromFile(f).toString());
    if (verifier.verify())
        System.out.println("Signature 1 - verification passed");
    else//from   ww  w . ja  va 2  s .  c  om
        System.out.println("Signature 1 - verification failed");

    File f2 = new File("c:\\temp\\sigout2.xml");
    org.w3c.dom.Document doc2 = db.parse(new java.io.FileInputStream(f2));

    // Note the apache api requires that you pass in a base uri, the location where the 
    // signature file is fine, if you do not know this (i.e in the case where the signature
    // file has not been saved), then just pass in "file:", as it works!!
    SignatureVerifier verifier2 = new SignatureVerifier(doc2, "file:");
    if (verifier2.verify())
        System.out.println("Signature 2 - verification passed");
    else
        System.out.println("Signature 2 - verification failed");

    File f3 = new File("c:\\temp\\vordelsig.xml");
    org.w3c.dom.Document doc3 = db.parse(new java.io.FileInputStream(f3));
    SignatureVerifier verifier3 = new SignatureVerifier(doc3, XngrURLUtilities.getURLFromFile(f3).toString());
    if (verifier3.verify())
        System.out.println("Vordel Signature - verification passed");
    else
        System.out.println("Vordel Signature - verification failed");

    File f4 = new File("c:\\temp\\license.xml");
    org.w3c.dom.Document doc4 = db.parse(new java.io.FileInputStream(f4));
    SignatureVerifier verifier4 = new SignatureVerifier(doc4, XngrURLUtilities.getURLFromFile(f4).toString());
    if (verifier4.verify())
        System.out.println("License Signature - verification passed");
    else
        System.out.println("License Signature - verification failed");

}

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);/*from w w w . j  a va  2s  .  c  om*/
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            editTextbyInsertionandReplacement(doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);//from ww  w . j  a  v  a2s .  com
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            addAttribute(doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);//w w  w . j a  v  a 2 s  . c  o  m
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            delAttribute(doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);//w w w.  j  av  a 2s.  com
        dbf.setNamespaceAware(true);
        dbf.setIgnoringElementContentWhitespace(true);

        Document doc = null;
        try {
            DocumentBuilder builder = dbf.newDocumentBuilder();
            builder.setErrorHandler(new MyErrorHandler());
            InputSource is = new InputSource("personWithDTD.xml");
            doc = builder.parse(is);

            deleteFirstElement(doc);

            write(doc);
        } catch (Exception e) {
            System.err.println(e);
        }
    }

From source file:DOMDump.java

static public void main(String[] arg) {
    String filename = null;/*from   w  w  w .  j ava2s  .  c om*/
    boolean validate = false;

    if (arg.length == 1) {
        filename = arg[0];
    } else if (arg.length == 2) {
        if (!arg[0].equals("-v"))
            usage();
        validate = true;
        filename = arg[1];
    } else {
        usage();
    }

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setValidating(validate);
    dbf.setNamespaceAware(true);
    dbf.setIgnoringElementContentWhitespace(true);

    // Parse the input to produce a parse tree with its root
    // in the form of a Document object
    Document doc = null;
    try {
        DocumentBuilder builder = dbf.newDocumentBuilder();
        builder.setErrorHandler(new MyErrorHandler());
        InputSource is = new InputSource(filename);
        doc = builder.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (ParserConfigurationException e) {
        System.err.println(e);
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }

    // Use a TreeDumper to list the tree
    TreeDumper td = new TreeDumper();
    td.dump(doc);
}