List of usage examples for org.xml.sax SAXException printStackTrace
public void printStackTrace()
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 . j av a2 s .co 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() == Document.ELEMENT_NODE) result.add(nl.item(i).getTextContent()); } } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; }
From source file:Main.java
/** * Creates W3C DOM Document object from XML file * @param filePath path to xml file including file name and extension *//*w w w . j av a2 s . co m*/ public static Document parseXml(String filePath) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(filePath); doc.getDocumentElement().normalize(); return doc; } catch (ParserConfigurationException pce) { pce.printStackTrace(); return null; } catch (SAXException se) { se.printStackTrace(); return null; } catch (IOException ioe) { ioe.printStackTrace(); return null; } }
From source file:Main.java
public static Document getDocument(InputStream xmlInputStream) { Document document = null;//from w ww.ja v a 2 s . c o m try { DocumentBuilder builder = docFactory.newDocumentBuilder(); document = builder.parse(xmlInputStream); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return document; }
From source file:Main.java
public static Document getDocument(String xmlString) { Document document = null;/*from w ww . j a v a 2 s. c o m*/ try { DocumentBuilder builder = docFactory.newDocumentBuilder(); document = builder.parse(new ByteArrayInputStream(xmlString.getBytes())); document.getDocumentElement().normalize(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return document; }
From source file:Main.java
public static boolean validate(URL schemaFile, String xmlString) { boolean success = false; try {//from w w w .j a v a 2 s . c o m SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = schemaFactory.newSchema(schemaFile); Validator validator = schema.newValidator(); Source xmlSource = null; try { xmlSource = new StreamSource(new java.io.StringReader(xmlString)); validator.validate(xmlSource); System.out.println("Congratulations, the document is valid"); success = true; } catch (SAXException e) { e.printStackTrace(); System.out.println(xmlSource.getSystemId() + " is NOT valid"); System.out.println("Reason: " + e.getLocalizedMessage()); } } catch (Exception e) { e.printStackTrace(); } return success; }
From source file:Main.java
public static Document parseData(String filename) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = null;/*from ww w. j a v a2s . c om*/ try { DocumentBuilder myDoc = factory.newDocumentBuilder(); File xmlFile = new File(filename); document = myDoc.parse(xmlFile); } 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 getDocument(InputStream xmlIs) { docFactory = getInstance();/*from w ww. jav a2 s . com*/ Document document = null; try { DocumentBuilder builder = docFactory.newDocumentBuilder(); document = builder.parse(xmlIs); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return document; }
From source file:Main.java
public static Document getDocument(String xmlStr) { docFactory = getInstance();/*from w w w . j ava 2s. c om*/ Document document = null; try { DocumentBuilder builder = docFactory.newDocumentBuilder(); document = builder.parse(new ByteArrayInputStream(xmlStr.getBytes())); document.getDocumentElement().normalize(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return document; }
From source file:Main.java
public static Document createDomDocument(String fileName) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = null;/*from w w w . j a v a2 s.c o m*/ try { File file = new File(fileName); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(file); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return document; }
From source file:Main.java
/** * Creates W3C DOM Document object from XML file * @param filePath path to xml file including file name and extension *//*from www. j av a2 s .c o m*/ public static Document parseXml(String filePath) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(filePath); doc.getDocumentElement().normalize(); return doc; } catch (ParserConfigurationException pce) { pce.printStackTrace(); return null; } catch (SAXException se) { se.printStackTrace(); return null; } catch (IOException ioe) { //ioe.printStackTrace(); String toRemove = File.separator + "WebApp" + File.separator; Document doc; try { DocumentBuilder db = dbf.newDocumentBuilder(); doc = db.parse(filePath.replace(toRemove, File.separator)); doc.getDocumentElement().normalize(); return doc; } catch (SAXException saxex) { saxex.printStackTrace(); return null; } catch (ParserConfigurationException pcex) { pcex.printStackTrace(); return null; } catch (IOException ioex) { ioex.printStackTrace(); return null; } } }