List of usage examples for org.xml.sax InputSource InputSource
public InputSource(Reader characterStream)
From source file:SimpleEntityResolver.java
public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException { if (systemID.equals(USAGE_TERMS_ID)) { return new InputSource(USAGE_TERMS_LOCAL_URI); }// ww w . j a v a 2s .com return null; }
From source file:Main.java
public static void formatXML(Reader xml, Reader xsl, URIResolver resolver, Writer output) throws Exception { try {/*from w ww .j a v a 2 s .c o m*/ try { try { Source xmlSource = new SAXSource(new InputSource(xml)); Source xslSource = new SAXSource(new InputSource(xsl)); Result result = new StreamResult(output); formatXML(xmlSource, xslSource, resolver, result); } finally { output.close(); } } finally { xsl.close(); } } finally { xml.close(); } }
From source file:Main.java
/** * Parses a XML document./* w w w . j a va2 s .c o m*/ * * @param xml the XML document * @return DOM */ public static Document parse(String xml) throws ParserConfigurationException, SAXException, IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new StringReader(xml))); removeWhitespaces((Element) document.getChildNodes().item(0)); return document; }
From source file:Main.java
/** * Evaluates the XPath expression against the <code>xml</code> and returns the selected value. * /*from w ww . j a v a2 s .c om*/ * @param expression Expression to evaluate. * @param xml The xml to query. * @return The selected value. * @throws XPathExpressionException If an error occurs evaluating the expression. */ public static String getValue(final String expression, final String xml) throws XPathExpressionException { final InputSource source = new InputSource(new StringReader(xml)); final XPathFactory factory = XPathFactory.newInstance(); final XPath xpath = factory.newXPath(); return xpath.evaluate(expression, source); }
From source file:Main.java
public static Document parseXmlText(String xml) { ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); return parseXmlInputSource(new InputSource(bais)); }
From source file:Main.java
/** * Parses XML document//from w w w. ja v a 2 s .c o m * @param string XML document as string * @return XML document as object * @throws IOException if error reading document * @throws SAXException if provided string is not an XML * @throws ParserConfigurationException if unable to create parser */ public static Document toDocument(String string) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = factory.newDocumentBuilder(); return builder.parse(new InputSource(new StringReader(string))); }
From source file:jp.go.nict.langrid.commons.jxpath.JXPathUtil.java
/** * // w ww .j a va2 s . co m * */ public static JXPathContext newXMLContext(String anXml) throws IOException, SAXException { DocumentBuilder builder = DocumentUtil.newDocumentBuilder(); return JXPathContext.newContext(builder.parse(new InputSource(new StringReader(anXml)))); }
From source file:Main.java
public static final boolean isWellFormedXml(final String string) throws Exception { return isWellFormedXml(new InputSource(new StringReader(string))); }
From source file:Main.java
public static Document getXMLDocument(String xmlContent) { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); Document xmlDocument = null;//from w w w.ja va 2s. c o m builderFactory.setValidating(false); builderFactory.setNamespaceAware(true); try { DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); try { xmlDocument = documentBuilder.parse(new InputSource(new StringReader(xmlContent))); } catch (SAXException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } } catch (ParserConfigurationException e) { throw new RuntimeException(e); } return xmlDocument; }
From source file:Main.java
public static Document createDocument(InputSource inputSource) throws SAXException, ParserConfigurationException, IOException { Document doc = null;/*from w w w. j a v a2 s.com*/ DocumentBuilderFactory factory = createDocumentBuilderFactory(); DocumentBuilder builder = createDocumentBuilder(factory); builder.setEntityResolver(new EntityResolver() { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new StringReader("")); } }); doc = builder.parse(inputSource); return doc; }