Example usage for org.xml.sax SAXException printStackTrace

List of usage examples for org.xml.sax SAXException printStackTrace

Introduction

In this page you can find the example usage for org.xml.sax SAXException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:XMLInfo.java

public static void main(String args[]) {
    try {//from   www.j a  v a  2 s . c om
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document document = builder.parse("xmlFileName.xml");
        Node root = document.getDocumentElement();
        System.out.print("Here is the document's root node:");
        System.out.println(" " + root.getNodeName());
        System.out.println("Here are its child elements: ");
        NodeList childNodes = root.getChildNodes();
        Node currentNode;

        for (int i = 0; i < childNodes.getLength(); i++) {
            currentNode = childNodes.item(i);
            System.out.println(currentNode.getNodeName());
        }

        // get first child of root element
        currentNode = root.getFirstChild();

        System.out.print("The first child of root node is: ");
        System.out.println(currentNode.getNodeName());

        // get next sibling of first child
        System.out.print("whose next sibling is: ");
        currentNode = currentNode.getNextSibling();
        System.out.println(currentNode.getNodeName());

        // print value of next sibling of first child
        System.out.println("value of " + currentNode.getNodeName() + " element is: "
                + currentNode.getFirstChild().getNodeValue());

        // print name of parent of next sibling of first child
        System.out.print("Parent node of " + currentNode.getNodeName() + " is: "
                + currentNode.getParentNode().getNodeName());
    }
    // handle exception creating DocumentBuilder
    catch (ParserConfigurationException parserError) {
        System.err.println("Parser Configuration Error");
        parserError.printStackTrace();
    }

    // handle exception reading data from file
    catch (IOException fileException) {
        System.err.println("File IO Error");
        fileException.printStackTrace();
    }

    // handle exception parsing XML document
    catch (SAXException parseException) {
        System.err.println("Error Parsing Document");
        parseException.printStackTrace();
    }
}

From source file:com.mirth.connect.plugins.datatypes.ncpdp.test.NCPDPTest.java

public static void main(String[] args) throws Exception {
    String testMessage = "";
    ArrayList<String> testFiles = new ArrayList<String>();
    testFiles.add("C:\\NCPDP_51_B1_Request.txt");
    testFiles.add("C:\\NCPDP_51_B1_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v6.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v7.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v8.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v9.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B3_Request.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Request.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_N1_Request.txt");
    testFiles.add("C:\\NCPDP_51_N2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_P2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P2_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Request.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P4_Request.txt");
    testFiles.add("C:\\NCPDP_51_P4_Response.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_1.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_2.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_3.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_4.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_5.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_6.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_7.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_8.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_9.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_10.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_11.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_12.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_13.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_14.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_15.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_16.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_17.txt");

    for (String testFile : testFiles) {
        testMessage = new String(FileUtils.readFileToByteArray(new File(testFile)));
        System.out.println("Processing test file:" + testFile);

        try {/*from  w w w.  j a  v  a2  s .  com*/
            long totalExecutionTime = 0;
            int iterations = 1;
            for (int i = 0; i < iterations; i++) {
                totalExecutionTime += runTest(testMessage);
            }

            //System.out.println("Execution time average: " + totalExecutionTime/iterations + " ms");
        }
        // System.out.println(new X12Serializer().serialize("SEG*1*2**4*5"));
        catch (SAXException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:OldExtractor.java

/**
 * @param args the command line arguments
 *//*from w w  w  . j av  a2s  .c o m*/
public static void main(String[] args) {
    // TODO code application logic here
    String bingUrl = "https://api.datamarket.azure.com/Bing/Search/Web?$top=10&$format=Atom&Query=%27gates%27";
    //Provide your account key here.
    String accountKey = "ghTYY7wD6LpyxUO9VRR7e1f98WFhHWYERMcw87aQTqQ";
    //  String accountKey = "xqbCjT87/MQz25JWdRzgMHdPkGYnOz77IYmP5FUIgC8";

    byte[] accountKeyBytes = Base64.encodeBase64((accountKey + ":" + accountKey).getBytes());
    String accountKeyEnc = new String(accountKeyBytes);

    try {
        URL url = new URL(bingUrl);
        URLConnection urlConnection = url.openConnection();

        urlConnection.setRequestProperty("Authorization", "Basic " + accountKeyEnc);
        InputStream inputStream = (InputStream) urlConnection.getContent();
        byte[] contentRaw = new byte[urlConnection.getContentLength()];
        inputStream.read(contentRaw);
        String content = new String(contentRaw);
        //System.out.println(content);
        try {
            File file = new File("Results.xml");
            FileWriter fileWriter = new FileWriter(file);
            fileWriter.write(content);
            //fileWriter.write("a test");
            fileWriter.flush();
            fileWriter.close();

        } catch (IOException e) {
            System.out.println(e);
        }

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        try {
            //System.out.println("here");
            //Using factory get an instance of document builder
            DocumentBuilder db = dbf.newDocumentBuilder();

            //parse using builder to get DOM representation of the XML file
            Document dom = db.parse("Results.xml");
            Element docEle = (Element) dom.getDocumentElement();

            //get a nodelist of elements

            NodeList nl = docEle.getElementsByTagName("d:Url");
            if (nl != null && nl.getLength() > 0) {
                for (int i = 0; i < nl.getLength(); i++) {

                    //get the employee element
                    Element el = (Element) nl.item(i);
                    // System.out.println("here");
                    System.out.println(el.getTextContent());

                    //get the Employee object
                    //Employee e = getEmployee(el);

                    //add it to list
                    //myEmpls.add(e);
                }
            }
            NodeList n2 = docEle.getElementsByTagName("d:Title");
            if (n2 != null && n2.getLength() > 0) {
                for (int i = 0; i < n2.getLength(); i++) {

                    //get the employee element
                    Element e2 = (Element) n2.item(i);
                    // System.out.println("here");
                    System.out.println(e2.getTextContent());

                    //get the Employee object
                    //Employee e = getEmployee(el);

                    //add it to list
                    //myEmpls.add(e);
                }
            }

            NodeList n3 = docEle.getElementsByTagName("d:Description");
            if (n3 != null && n3.getLength() > 0) {
                for (int i = 0; i < n3.getLength(); i++) {

                    //get the employee element
                    Element e3 = (Element) n3.item(i);
                    // System.out.println("here");
                    System.out.println(e3.getTextContent());

                    //get the Employee object
                    //Employee e = getEmployee(el);

                    //add it to list
                    //myEmpls.add(e);
                }
            }

        } catch (SAXException se) {
            se.printStackTrace();
        } catch (ParserConfigurationException pe) {
            pe.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

    } catch (IOException e) {
        System.out.println(e);
    }

    //The content string is the xml/json output from Bing.

}

From source file:com.mirth.connect.model.converters.tests.NCPDPTest.java

public static void main(String[] args) throws Exception {
    String testMessage = "";
    ArrayList<String> testFiles = new ArrayList<String>();
    testFiles.add("C:\\NCPDP_51_B1_Request.txt");
    testFiles.add("C:\\NCPDP_51_B1_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v6.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v7.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v8.txt");
    testFiles.add("C:\\NCPDP_51_B1_Response_v9.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request.txt");
    testFiles.add("C:\\NCPDP_51_B2_Request_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B2_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_B3_Request.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_B3_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Request.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v4.txt");
    testFiles.add("C:\\NCPDP_51_E1_Response_v5.txt");
    testFiles.add("C:\\NCPDP_51_N1_Request.txt");
    testFiles.add("C:\\NCPDP_51_N2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Request.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P1_Response_v3.txt");
    testFiles.add("C:\\NCPDP_51_P2_Request.txt");
    testFiles.add("C:\\NCPDP_51_P2_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Request.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response.txt");
    testFiles.add("C:\\NCPDP_51_P3_Response_v2.txt");
    testFiles.add("C:\\NCPDP_51_P4_Request.txt");
    testFiles.add("C:\\NCPDP_51_P4_Response.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_1.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_2.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_3.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_4.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_5.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_6.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_7.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_8.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_9.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_10.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_11.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_12.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_13.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_14.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_15.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_16.txt");
    testFiles.add("C:\\NCPDP_51_CALPOS_17.txt");

    for (String testFile : testFiles) {
        testMessage = new String(FileUtils.readFileToByteArray(new File(testFile)));
        System.out.println("Processing test file:" + testFile);

        try {//from ww  w  .  j  a v  a2 s . c  o m
            long totalExecutionTime = 0;
            int iterations = 1;
            for (int i = 0; i < iterations; i++) {
                totalExecutionTime += runTest(testMessage);
            }

            //System.out.println("Execution time average: " + totalExecutionTime/iterations + " ms");
        }
        // System.out.println(new X12Serializer().toXML("SEG*1*2**4*5"));
        catch (SAXException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

From source file:de.zib.scalaris.examples.wikipedia.data.xml.Main.java

/**
 * The main function of the application. Some articles are blacklisted and
 * will not be processed (see implementation for a list of them).
 * /*from  w w  w . j av a2  s.  c o  m*/
 * @param args
 *            first argument should be the xml file to convert.
 */
public static void main(String[] args) {
    try {
        String filename = args[0];

        if (args.length > 1) {
            if (args[1].equals("filter")) {
                doFilter(filename, Arrays.copyOfRange(args, 2, args.length));
            } else if (args[1].equals("import-xml")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.IMPORT_XML);
            } else if (args[1].equals("import-db")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.IMPORT_DB);
            } else if (args[1].equals("prepare")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.PREPARE_DB);
            } else if (args[1].equals("xml2db")) {
                doImport(filename, Arrays.copyOfRange(args, 2, args.length), ImportType.XML_2_DB);
            } else if (args[1].equals("convert")) {
                doConvert(filename, Arrays.copyOfRange(args, 2, args.length));
            } else if (args[1].equals("dumpdb-addlinks")) {
                doDumpdbAddlinks(filename, Arrays.copyOfRange(args, 2, args.length));
            } else if (args[1].equals("dumpdb-filter")) {
                doDumpdbFilter(filename, Arrays.copyOfRange(args, 2, args.length));
            }
        }
    } catch (SAXException e) {
        System.err.println(e.getMessage());
        System.exit(-1);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.exit(-1);
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:Main.java

public static Document getDocument(String fileName) {
    Document document = null;/*from w w  w. j a  v a  2  s  .co  m*/
    try {
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
        document = documentBuilder.parse(fileName);

    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return document;
}

From source file:Main.java

public static Document getDocumentForStream(InputStream stream) {
    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = null;
    Document doc = null;//from w  w w . j av  a 2  s  . c  om
    try {
        docBuilder = docBuilderFactory.newDocumentBuilder();
        doc = docBuilder.parse(stream);
        doc.getDocumentElement().normalize();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return doc;
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {
    LinkedList result = new LinkedList();

    DOMParser parser = new DOMParser();
    try {//from   www  .ja  va2  s  . c om
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++)
            if (nl.item(i).getNodeType() == 1)
                result.add(nl.item(i).getTextContent());
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {
    LinkedList result = new LinkedList();

    DOMParser parser = new DOMParser();
    try {/*w  w  w.  ja  v a  2 s . c  o  m*/
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; ++i)
            if (nl.item(i).getNodeType() == 1)
                result.add(nl.item(i).getTextContent());
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {

    LinkedList<String> result = new LinkedList<String>();

    DOMParser parser = new DOMParser();
    try {/*  w w w .ja v  a 2s .c  om*/
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++) {
            if (nl.item(i).getNodeType() == Document.ELEMENT_NODE)
                result.add(nl.item(i).getNodeValue());
        }
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}