Example usage for org.xml.sax InputSource setCharacterStream

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

Introduction

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

Prototype

public void setCharacterStream(Reader characterStream) 

Source Link

Document

Set the character stream for this input source.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    cdata.appendData("from java2s.com");
    System.out.println(cdataNode.getLength());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    cdata.setData("from java2s.com");
    System.out.println(cdataNode.substringData(2, 4));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    cdata.setData("from java2s.com");
    System.out.println(cdataNode);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    cdata.appendData("from java2s.com");
    cdata.deleteData(1, 2);/*ww  w.  j a  va  2s. c  o m*/
    System.out.println(cdataNode);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    cdata.appendData("from java2s.com");
    cdata.deleteData(1, 2);/*from   w  w  w. ja v  a 2s.  c om*/
    System.out.println(cdataNode.getData());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    cdata.appendData("from java2s.com");
    System.out.println(cdataNode);
    cdata.replaceData(1, 2, "new");
    System.out.println(cdataNode);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = factory.newDocumentBuilder().parse(is);

    CDATASection cdataNode = doc.createCDATASection("");

    CharacterData cdata = cdataNode;

    int offset = 0;
    cdata.insertData(offset, "a ");
    cdata.appendData(" b");
    System.out.println(cdataNode);
}

From source file:Main.java

public static void main(String arg[]) throws Exception {
    String xmlRecords = "<root><x>1</x><x>2</x><x>3</x><x>4</x></root>";
    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = db.parse(is);/*from  w ww. j  a v  a 2s.  c o m*/
    NodeList nodes = doc.getElementsByTagName("x");
    System.out.println(nodes.getLength());
    List<String> valueList = new ArrayList<String>();
    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);
        String name = element.getTextContent();
        // Element line = (Element) name.item(0);
        System.out.println("Name: " + name);
        valueList.add(name);
    }
}

From source file:Main.java

public static void main(String arg[]) throws Exception {
    String xmlRecords = "<data><employee><name>A</name>" + "<title>Manager</title></employee></data>";

    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xmlRecords));

    Document doc = db.parse(is);//  w  w  w. jav a  2  s  . c o  m
    NodeList nodes = doc.getElementsByTagName("employee");

    for (int i = 0; i < nodes.getLength(); i++) {
        Element element = (Element) nodes.item(i);

        NodeList name = element.getElementsByTagName("name");
        Element line = (Element) name.item(0);
        System.out.println("Name: " + getCharacterDataFromElement(line));

        NodeList title = element.getElementsByTagName("title");
        line = (Element) title.item(0);
        System.out.println("Title: " + getCharacterDataFromElement(line));
    }

}

From source file:Main.java

public static Document domFromString(String in) {
    try {//from  w w  w.  ja  v a 2  s.  co m
        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(in));
        return db.parse(is);
    } catch (ParserConfigurationException | SAXException | IOException ex) {
        throw new RuntimeException("Unable to parse xml.", ex);
    }
}