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 parseXml(String xml) {
    try {/*  w ww.  j a  v a2s.c o m*/
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        dbFactory.setNamespaceAware(true);
        setUpSecurity(dbFactory);
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        return dBuilder.parse(new InputSource(new StringReader(xml)));
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Document toXML(InputStream input) {
    return toXML(new InputSource(input));
}

From source file:Main.java

public static List<Node> xPathEvalListNodes(String content, String expression) throws XPathExpressionException {
    List<Node> retValues = new ArrayList<Node>();
    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));/*from   w ww  .ja  v a  2s.co m*/
    }

    return retValues;
}

From source file:Main.java

/** Forms an <code>InputSource</code> for parsing XML documents
 *  from a file. Assumes a default character encoding. Returns
 *  <code>null</code> if any of the exceptions is thrown.
 *
 * @param fileName The name of the file.
 * @return An <code>InputSource</code> representation.
 *//*from   www  .j  a v a  2 s .  c  o m*/
public static InputSource getInputSource(String fileName) {
    InputSource retVal = null;
    try {
        retVal = new InputSource(new BufferedReader(new FileReader(fileName)));
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
    return retVal;
}

From source file:Main.java

public static Document parseXmlString(String resp)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    return builder.parse(new InputSource(new StringReader(resp)));
}

From source file:Main.java

public static Document string2doc(String xml) throws SAXException, ParserConfigurationException, IOException {
    DocumentBuilder builder = builderFac.newDocumentBuilder();
    return builder.parse(new InputSource(new StringReader(xml)));
}

From source file:Main.java

public static Node parseXML(String text) throws SAXException, ParserConfigurationException, IOException {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder parser = dbf.newDocumentBuilder();
    InputSource source = new InputSource(new StringReader(text));
    Document doc = parser.parse(source);
    if (doc == null) {
        throw new NullPointerException();
    }//w  w w .  j  a va 2  s  . c o  m

    return doc.getFirstChild();
}

From source file:Main.java

public static Document convertStringToDocument(String xmlStr)
        throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    return builder.parse(new InputSource(new StringReader(xmlStr)));
}

From source file:Main.java

public static Document stringToDocument(String xml) {
    Document doc = null;/* ww w .j a v a  2 s  . c  om*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    // Turn on validation, and turn off namespaces
    factory.setValidating(false);
    factory.setNamespaceAware(false);

    try {
        DocumentBuilder builder = factory.newDocumentBuilder();
        doc = builder.parse(new InputSource(new StringReader(xml)));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return doc;
}

From source file:Main.java

public static Document parse(String xml) throws Exception {
    return newBuilder().parse(new InputSource(new StringReader(xml)));
}