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 void main(String[] args) throws Exception {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();

    NodeList shows = (NodeList) xPath.evaluate("/schedule/show", new InputSource(new FileReader("tds.xml")),
            XPathConstants.NODESET);
    for (int i = 0; i < shows.getLength(); i++) {
        Element show = (Element) shows.item(i);
        String guestName = xPath.evaluate("guest/name", show);
        System.out.println(guestName);
        System.out.println(show.getAttribute("weekday") + ", " + show.getAttribute("date"));
    }/*from w w w.  j  av  a  2s  .c  om*/

}

From source file:Main.java

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

    Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData())));

    visit(doc, 0);/*from   w  ww. j  av  a 2s  .  com*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    XPathFactory xpf = XPathFactory.newInstance();
    XPath xPath = xpf.newXPath();

    InputSource inputSource = new InputSource(new StringReader(XML));
    String result = (String) xPath.evaluate("//gender", inputSource, XPathConstants.STRING);
    System.out.println(result);//from  w  w  w .j  a v a 2s.  c  o m
}

From source file:GuestList.java

public static void main(String[] args) throws Exception {
    XPathFactory factory = XPathFactory.newInstance();
    XPath xPath = factory.newXPath();

    NodeList shows = (NodeList) xPath.evaluate("/schedule/show", new InputSource(new FileReader("tds.xml")),
            XPathConstants.NODESET);
    for (int i = 0; i < shows.getLength(); i++) {
        Element show = (Element) shows.item(i);
        String guestName = xPath.evaluate("guest/name", show);
        String guestCredit = xPath.evaluate("guest/credit", show);

        System.out.println(show.getAttribute("weekday") + ", " + show.getAttribute("date") + " - " + guestName
                + " (" + guestCredit + ")");
    }// w w w . j  ava  2s.  co m

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData())));

    Element root = doc.getDocumentElement();
    EntityReference eref = (EntityReference) root.getFirstChild();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData())));
    NodeList list = doc.getElementsByTagName("*");
    for (int i = 0; i < list.getLength(); i++) {
        Element element = (Element) list.item(i);
        System.out.println(element);
    }//from   w w w  .j av  a2 s  . co  m
}

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser
    Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString)));

    Text text = xmlDoc.createTextNode("text");

}

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser
    Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString)));

    Attr attr = xmlDoc.createAttribute("text");

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String xml = "<!DOCTYPE html><hml><img/></hml>";
    SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
    InputSource in = new InputSource(new StringReader(xml));

    DefaultHandler2 myHandler = new DefaultHandler2() {
        @Override/*from www. j  a va  2s.  com*/
        public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {
            System.out.println("Element: " + qName);
        }

        @Override
        public void startDTD(String name, String publicId, String systemId) throws SAXException {
            System.out.println("DocType: " + name);
        }
    };
    saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", myHandler);
    saxParser.parse(in, myHandler);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    Document doc = factory.newDocumentBuilder().parse(new InputSource(new StringReader(getXMLData())));

    NamedNodeMap notations = doc.getDoctype().getNotations();

    for (int i = 0; i < notations.getLength(); i++) {
        Notation notation = (Notation) notations.item(i);

        String notationName = notation.getNodeName();
        System.out.println(notationName);
        String notationPublicId = notation.getPublicId();
        String notationSystemId = notation.getSystemId();
    }//from  w  w w.j a v a  2 s.  com
}