@Test public void testFromDocumentDoesNotWriteToStderrWhenXmlInvalid() throws SAXException, IOException, ParserConfigurationException { PrintStream err = System.err; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try { PrintStream err2 = new PrintStream(bytes); System.setErr(err2); XpathUtils.documentFrom("a"); Assert.fail(); } catch (SAXParseException e) { assertEquals(0, bytes.toByteArray().length); } finally { System.setErr(err); } }
public static Document documentFrom(InputStream is) throws SAXException, IOException, ParserConfigurationException { is = new NamespaceRemovingInputStream(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(ERROR_HANDLER); Document doc = builder.parse(is); is.close(); return doc; }
XpathUtils { public static Document documentFrom(InputStream is) throws SAXException, IOException, ParserConfigurationException { is = new NamespaceRemovingInputStream(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(ERROR_HANDLER); Document doc = builder.parse(is); is.close(); return doc; } }
XpathUtils { public static Document documentFrom(InputStream is) throws SAXException, IOException, ParserConfigurationException { is = new NamespaceRemovingInputStream(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(ERROR_HANDLER); Document doc = builder.parse(is); is.close(); return doc; }  }
XpathUtils { public static Document documentFrom(InputStream is) throws SAXException, IOException, ParserConfigurationException { is = new NamespaceRemovingInputStream(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(ERROR_HANDLER); Document doc = builder.parse(is); is.close(); return doc; }  static XPath xpath(); static Document documentFrom(InputStream is); static Document documentFrom(String xml); static Document documentFrom(URL url); static Double asDouble(String expression, Node node); static Double asDouble(String expression, Node node, XPath xpath); static String asString(String expression, Node node); static String asString(String expression, Node node, XPath xpath); static Integer asInteger(String expression, Node node); static Integer asInteger(String expression, Node node, XPath xpath); static Boolean asBoolean(String expression, Node node); static Boolean asBoolean(String expression, Node node, XPath xpath); static Float asFloat(String expression, Node node); static Float asFloat(String expression, Node node, XPath xpath); static Long asLong(String expression, Node node); static Long asLong(String expression, Node node, XPath xpath); static Byte asByte(String expression, Node node); static Byte asByte(String expression, Node node, XPath xpath); static Date asDate(String expression, Node node); static Date asDate(String expression, Node node, XPath xpath); static ByteBuffer asByteBuffer(String expression, Node node); static ByteBuffer asByteBuffer(String expression, Node node, XPath xpath); static boolean isEmpty(Node node); static Node asNode(String nodeName, Node node); static Node asNode(String nodeName, Node node, XPath xpath); static int nodeLength(NodeList list); }
XpathUtils { public static Document documentFrom(InputStream is) throws SAXException, IOException, ParserConfigurationException { is = new NamespaceRemovingInputStream(is); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); builder.setErrorHandler(ERROR_HANDLER); Document doc = builder.parse(is); is.close(); return doc; }  static XPath xpath(); static Document documentFrom(InputStream is); static Document documentFrom(String xml); static Document documentFrom(URL url); static Double asDouble(String expression, Node node); static Double asDouble(String expression, Node node, XPath xpath); static String asString(String expression, Node node); static String asString(String expression, Node node, XPath xpath); static Integer asInteger(String expression, Node node); static Integer asInteger(String expression, Node node, XPath xpath); static Boolean asBoolean(String expression, Node node); static Boolean asBoolean(String expression, Node node, XPath xpath); static Float asFloat(String expression, Node node); static Float asFloat(String expression, Node node, XPath xpath); static Long asLong(String expression, Node node); static Long asLong(String expression, Node node, XPath xpath); static Byte asByte(String expression, Node node); static Byte asByte(String expression, Node node, XPath xpath); static Date asDate(String expression, Node node); static Date asDate(String expression, Node node, XPath xpath); static ByteBuffer asByteBuffer(String expression, Node node); static ByteBuffer asByteBuffer(String expression, Node node, XPath xpath); static boolean isEmpty(Node node); static Node asNode(String nodeName, Node node); static Node asNode(String nodeName, Node node, XPath xpath); static int nodeLength(NodeList list);  }