List of usage examples for org.xml.sax SAXException printStackTrace
public void printStackTrace()
From source file:Main.java
public static Document toXMLDocument(InputSource source) { Document xmlDoc = null;//w w w .j av a 2s .c o m try { xmlDoc = getBuilder().parse(source); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return xmlDoc; }
From source file:Main.java
/** * * @param fileName/*from w w w. j a va2 s. c o m*/ * @return */ // public static Document createDomDocument(String fileName) { public static Document createDomDocument(URI fileName) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); Document document = null; try { // File file = new File(fileName); java.io.InputStream is = fileName.toURL().openStream(); DocumentBuilder builder = factory.newDocumentBuilder(); // document = builder.parse(file); document = builder.parse(is); } 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
/** * This method parses an XML file and returns an {@code org.w3c.dom.Document} * @param f//www . j a va 2 s . c o m * @return */ public static Document parseXMLFile(File f) { Document dom = null; // get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file dom = db.parse(f); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } return dom; }
From source file:Main.java
/** * Converts String containing XML code to Document * /*from w w w .ja v a 2 s.c o m*/ * @param xmlString * @return <code>Document</code> interface */ public static Document stringToDocument(String xmlString) { if (xmlString == null) return null; DocumentBuilder documentBuilder = getDocumentBuilder(); InputSource inputSource = new InputSource(new StringReader(xmlString)); try { return documentBuilder.parse(inputSource); } catch (SAXException e) { e.printStackTrace(); return null; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:Main.java
public static ArrayList<String> getFontSizeList() { ArrayList<String> fontList = new ArrayList<String>(); DocumentBuilderFactory dbfFont = null; DocumentBuilder dbFont = null; Document domFont = null;/*from ww w. j a v a 2 s . c o m*/ try { dbfFont = DocumentBuilderFactory.newInstance(); String fontSizeFileName = "resources/FontSizes.xml"; //Using factory get an instance of document builder dbFont = dbfFont.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file domFont = dbFont.parse(fontSizeFileName); //get the root elememt Element docEle = domFont.getDocumentElement(); //get a nodelist of <sizes> elements NodeList sizeList = docEle.getElementsByTagName("size"); if (sizeList != null && sizeList.getLength() > 0) { for (int i = 0; i < sizeList.getLength(); i++) { //get the employee element Element sizeElement = (Element) sizeList.item(i); fontList.add(sizeElement.getTextContent()); } } } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace(); } catch (IOException ioe) { ioe.printStackTrace(); } return fontList; }
From source file:Main.java
public static Node loadURL(java.net.URL url) { Document document = null;/*from w w w . j a v a 2 s.c o m*/ if (url != null) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); document = builder.parse(url.openStream()); } catch (java.io.IOException ioe) { document = null; ioe.printStackTrace(); } catch (ParserConfigurationException pce) { document = null; pce.printStackTrace(); } catch (org.xml.sax.SAXException se) { document = null; se.printStackTrace(); } return document; } return null; }
From source file:Main.java
/** * Read application-context file, and return fully qualified class name for * given <code>beanName</code> * // ww w . j a v a2 s. c om * @param beanName * @return * */ public static String getFullyQualifiedClass(String beanName) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); String nodeValue = ""; try { DocumentBuilder builder = docBuilderFactory.newDocumentBuilder(); Document doc = builder.parse("application-context.xml"); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile("//bean[@name='" + beanName + "']/@class"); Object result = expr.evaluate(doc, XPathConstants.NODESET); NodeList nodes = (NodeList) result; if (nodes.getLength() > 0) { nodeValue = nodes.item(0).getNodeValue(); } } catch (ParserConfigurationException parserConfigurationException) { parserConfigurationException.printStackTrace(); } catch (IOException ioException) { ioException.printStackTrace(); } catch (SAXException saxException) { saxException.printStackTrace(); } catch (XPathExpressionException xPathExpressionException) { xPathExpressionException.printStackTrace(); } return nodeValue; }
From source file:Main.java
public static final boolean isWellFormedXml(final InputSource isource) { try {/*from w w w . j av a 2 s . c om*/ newXMLReader().parse(isource); return true; } catch (SAXException e) { System.out.println(e); e.printStackTrace(); return false; } catch (IOException e) { throw new UndeclaredThrowableException(e); } catch (ParserConfigurationException e) { throw new UndeclaredThrowableException(e); } }
From source file:Main.java
/** * DOM Parser method. //from w w w .j av a 2s . com * Converts the input xmlString into List<String> of all the text in the nodes named nodeName. * The memory footprint is small enough when we deal with less than 200 tweets. * * @param xmlString * The xml string * @param nodeName * the name of the node, we are intersted in (e.g. "text") * @param trimString * if we want to trim a particular pattern from every node's text, we pass it as trimString, e.g. "(https?://[^\\s]+)" * @return List of all the text strings from every node named nodeName. trimString text is trimmed from the result strings. */ public static List<String> parseNodesFromXml(String xmlString, String nodeName, String trimString) { List<String> nodeTexts = new ArrayList<String>(); try { DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource inputSource = new InputSource(); inputSource.setCharacterStream(new StringReader(xmlString)); try { Document document = db.parse(inputSource); NodeList nodes = document.getElementsByTagName(nodeName); for (int i = 0; i < nodes.getLength(); i++) { String nodeText = nodes.item(i).getTextContent(); String trimmedNodeText = trimStringFromText(trimString, nodeText); nodeTexts.add(trimmedNodeText); } } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } catch (ParserConfigurationException e) { e.printStackTrace(); } return nodeTexts; }
From source file:Main.java
/** * @param schema//w w w . j a v a 2 s.c o m * @return */ private static Schema parseSchema(File schema) { Schema parsedSchema = null; SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { parsedSchema = sf.newSchema(schema); } catch (SAXException e) { // TODO Auto-generated catch block System.out.println("Problems parsing schema " + schema.getName()); e.printStackTrace(); } return parsedSchema; }