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() 

Source Link

Document

Zero-argument default constructor.

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);/*from w w w .  j  av  a  2 s .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 a2s  .c  o  m*/
    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);//w  w  w.  j  av  a  2s  . com
    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);// ww w .  j  a va 2  s.c  om
    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 String getNodeCount(String nodeName, String xmlString) {
    String response = "";
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();
    try {/*  w  w  w.j a  va  2 s  .co m*/
        XPathExpression xPathExpression = xPath.compile("count(//" + nodeName + ")");
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(xmlString));
        response = xPathExpression.evaluate(is);

    } catch (XPathExpressionException e) {
        e.printStackTrace();
    }

    return response;
}