Example usage for javax.xml.parsers DocumentBuilder setErrorHandler

List of usage examples for javax.xml.parsers DocumentBuilder setErrorHandler

Introduction

In this page you can find the example usage for javax.xml.parsers DocumentBuilder setErrorHandler.

Prototype


public abstract void setErrorHandler(ErrorHandler eh);

Source Link

Document

Specify the ErrorHandler to be used by the parser.

Usage

From source file:DOMEdit.java

static public void main(String[] arg) {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setValidating(true);/*from   w  ww . ja v a2  s  .  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);

            addProcessingInstruction(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. ja  v 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);

            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);//from   w  w w .  j  a v a 2  s . 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);

        insert(doc, "newName", "1111111111", "newEmail");

        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);/*www  . java2 s  . 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);

            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);/*from w w w  .j ava2 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);

            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  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);

            modifyingTextbyCuttingandPasting(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   w ww .j av a2 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);

            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);//  www  .  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);

            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 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);

            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  ww  .  j  av a2 s  .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);

            deleteFirstElement(doc);

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