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 LinkedList<String> uc_unserialize(String input) {
    LinkedList result = new LinkedList();

    DOMParser parser = new DOMParser();
    try {/*from  w  w w .ja  v a  2s .c o m*/
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++)
            if (nl.item(i).getNodeType() == 1)
                result.add(nl.item(i).getTextContent());
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {
    LinkedList result = new LinkedList();

    DOMParser parser = new DOMParser();
    try {//from w ww  .  ja  v a2s. c  om
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; ++i)
            if (nl.item(i).getNodeType() == 1)
                result.add(nl.item(i).getTextContent());
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static Document parse(String text) throws SAXException, IOException, ParserConfigurationException {
    return getDocumentBuilder().parse(new InputSource(new StringReader(text)));
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {

    LinkedList<String> result = new LinkedList<String>();

    DOMParser parser = new DOMParser();
    try {// w w  w.j  av  a 2  s .  c  o m
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++) {
            if (nl.item(i).getNodeType() == Document.ELEMENT_NODE)
                result.add(nl.item(i).getNodeValue());
        }
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

private static Document buildDocument(InputStream in) throws Exception {
    DocumentBuilderFactory factory = null;
    DocumentBuilder builder = null;
    Document ret = null;/*from  www  .j  av a 2  s .  c  o  m*/

    factory = DocumentBuilderFactory.newInstance();
    builder = factory.newDocumentBuilder();

    ret = builder.parse(new InputSource(in));
    return ret;
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {

    LinkedList<String> result = new LinkedList<String>();

    DOMParser parser = new DOMParser();
    try {/*from  w  w  w. ja  v a  2s .  c  o  m*/
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++) {
            if (nl.item(i).getNodeType() == Document.ELEMENT_NODE)
                result.add(nl.item(i).getTextContent());
        }
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static Document convertStringToDocument(String domStr) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;/*w  w  w .jav a  2  s  . c o  m*/
    try {
        builder = factory.newDocumentBuilder();
        Document doc = builder.parse(new InputSource(new StringReader(domStr)));
        return doc;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static LinkedList<String> uc_unserialize(String input) {

    LinkedList<String> result = new LinkedList<String>();

    DOMParser parser = new DOMParser();
    try {/*  w  w w.j  a  v a  2  s  .  c  o m*/
        parser.parse(new InputSource(new StringReader(input)));
        Document doc = parser.getDocument();
        NodeList nl = doc.getChildNodes().item(0).getChildNodes();
        int length = nl.getLength();
        for (int i = 0; i < length; i++) {
            if (nl.item(i).getNodeType() == Document.ELEMENT_NODE)
                result.add(nl.item(i).getFirstChild().getNodeValue());
        }
    } catch (SAXException e) {

    } catch (IOException e) {

    }
    return result;
}

From source file:Main.java

/**
 * Forms an <code>InputSource</code> for parsing XML documents
 * from a string. Returns <code>null</code> if any of the exceptions
 * are thrown./* ww  w . j  a va 2  s  .  co m*/
 * 
 * @param xml String with the XML document.
 * @return An <code>InputSource</code> representation.
 */
public static InputSource getInputSourceFromString(String xml) {
    InputSource retVal = null;
    try {
        retVal = new InputSource(new StringReader(xml));
    } catch (Exception ex) {
    }
    return retVal;
}

From source file:Main.java

public static Document String2XML(String xmlStr) {
    try {//  w  w w.  j a  v  a  2  s. co  m
        StringReader sr = new StringReader(xmlStr);
        InputSource is = new InputSource(sr);
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        return builder.parse(is);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}