Example usage for org.xml.sax InputSource InputSource

List of usage examples for org.xml.sax InputSource InputSource

Introduction

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

Prototype

public InputSource(Reader characterStream) 

Source Link

Document

Create a new input source with a character stream.

Usage

From source file:Main.java

public static Document convertStringToXmlDocument(String xmlString) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;//from  w ww. ja  v  a 2 s  .  com
    try {
        factory.setNamespaceAware(true);
        builder = factory.newDocumentBuilder();
        Document doc = builder.parse(new InputSource(new StringReader(xmlString)));
        return doc;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean isValidXML(String xml) {
    try {/* w  w  w. jav  a2  s.  co m*/
        DocumentBuilder builder = dbf.newDocumentBuilder();
        Reader reader = null;
        try {
            reader = new StringReader(xml);
            builder.parse(new InputSource(reader));
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

public static Document getW3CDom(String xmlStr) throws ParserConfigurationException, SAXException, IOException {
    StringReader sr = new StringReader(xmlStr);
    InputSource is = new InputSource(sr);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(is);
    return doc;/*from w  w  w  . j av  a  2 s .  c om*/
}

From source file:Main.java

public static Document documentFromString(String xml) throws SAXException, IOException {

    Reader reader = new StringReader(xml);
    InputSource source = new InputSource(reader);
    DocumentBuilder db = newDocumentBuilder(false);
    return db.parse(source);
}

From source file:Main.java

public static Document StringToxml(String resultData) {

    StringReader sr = new StringReader(resultData);
    InputSource is = new InputSource(sr);
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    Document doc = null;// www .ja  v a 2  s  .  co m
    try {
        builder = factory.newDocumentBuilder();
    } catch (ParserConfigurationException e) {

        Log.e(DEBUG_TAG, "the StringToxml method ParserConfigurationException erro ");
    }
    try {
        doc = builder.parse(is);

    } catch (SAXException e) {

        Log.e(DEBUG_TAG, "the StringToxml method SAXException erro ");

    } catch (IOException e) {
        Log.e(DEBUG_TAG, "the StringToxml method IOException erro ");
    }
    return doc;
}

From source file:Main.java

public static Document load(URL url) {
    return load(new InputSource(url.toString()));
}

From source file:Main.java

private static Document getDocument(String xml) {
    try {/*from w  w  w . j a v  a 2 s.  c  o  m*/
        // Create a builder factory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);

        return factory.newDocumentBuilder().parse(new InputSource(new StringReader(xml)));
    } catch (SAXException e) {
        return null;
    } catch (ParserConfigurationException e) {
        return null;
    } catch (IOException e) {
        return null;
    }
}

From source file:Main.java

/**
 * Liefert das {@link Document} aus dem Byte-Array.
 * //from w w  w .  jav a 2  s .c  o m
 * @param bytes byte[]
 * @return {@link Document}
 * @throws Exception Falls was schief geht.
 */
public static Document getDocument(final byte[] bytes) throws Exception {
    return getDocument(new InputSource(new ByteArrayInputStream(bytes)));
}

From source file:Main.java

public static List<String> xPathEvalList(String content, String expression) throws XPathExpressionException {
    List<String> retValues = new ArrayList<String>();
    XPath xpath = XPathFactory.newInstance().newXPath();
    InputSource inputSource = new InputSource(new StringReader(content));
    NodeList ox = (NodeList) xpath.evaluate(expression, inputSource, XPathConstants.NODESET);
    for (int i = 0; i < ox.getLength(); i++) {
        retValues.add(ox.item(i).getNodeValue());
    }/*from  ww  w.  jav a  2  s.  c om*/

    return retValues;
}

From source file:Main.java

private static Document parseXmlFile(String in) {
    try {//w  w w.  j  a  va  2 s  .  c  o m
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(in));
        return db.parse(is);
    } catch (ParserConfigurationException | SAXException | IOException e) {
        throw new RuntimeException(e);
    }
}