Example usage for javax.xml.parsers SAXParserFactory newSAXParser

List of usage examples for javax.xml.parsers SAXParserFactory newSAXParser

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParserFactory newSAXParser.

Prototype


public abstract SAXParser newSAXParser() throws ParserConfigurationException, SAXException;

Source Link

Document

Creates a new instance of a SAXParser using the currently configured factory parameters.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.parsers.SAXParser");
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    SaxHandler handler = new SaxHandler();
    parser.parse("sample.xml", handler);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser parser = factory.newSAXParser();
    SaxHandler handler = new SaxHandler();
    parser.parse("sample.xml", handler);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    DefaultHandler handler = new DefaultHandler() {
        public void startElement(String uri, String localName, String qName, Attributes attributes)
                throws SAXException {
            System.out.println(qName);
        }/*from w w w  . j av  a 2 s.  c o m*/

        public void characters(char ch[], int start, int length) throws SAXException {
            System.out.println(new String(ch, start, length));
        }
    };

    saxParser.parse(args[0], handler);
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    String language = XMLConstants.W3C_XML_SCHEMA_NS_URI;
    SchemaFactory factory = SchemaFactory.newInstance(language);
    Schema schema = factory.newSchema(new File("yourSchema"));

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setSchema(schema);// w  w  w . j a  v  a  2  s.  c o  m

    SAXParser parser = spf.newSAXParser();

    // parser.parse(...);
}

From source file:FragmentContentHandler.java

public static void main(String[] args) throws Exception {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    SAXParser sp = spf.newSAXParser();
    XMLReader xr = sp.getXMLReader();

    xr.setContentHandler(new FragmentContentHandler(xr));
    xr.parse(new InputSource(new FileInputStream("input.xml")));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);//from ww  w  .ja v  a  2 s. com
    SAXParser parser = factory.newSAXParser();
    parser.parse("sample.xml", new Main());
}

From source file:MainClass.java

public static void main(String args[]) {
    try {/*from   w  ww. j a v a2  s. c  o m*/
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        DefaultHandler handler = new DefaultHandler() {
            boolean name = false;

            public void startElement(String uri, String localName, String qName, Attributes attributes)
                    throws SAXException {
                if (qName.equalsIgnoreCase("NAME")) {
                    name = true;
                }
            }

            public void characters(char ch[], int start, int length) throws SAXException {
                if (name) {
                    System.out.println("Name: " + new String(ch, start, length));
                    name = false;
                }
            }
        };

        saxParser.parse(new InputSource(new StringReader(xmlString)), handler);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);//w  w  w .j  a v  a2s .com
    SAXParser parser = factory.newSAXParser();
    parser.parse("sample.xml", new SampleOfXmlLocator());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(true);/*from w ww.  j a  v  a 2s  .c  om*/
    SAXParser parser = factory.newSAXParser();
    SaxHandler handler = new SaxHandler();
    parser.parse(new InputSource(new StringReader(getXMLData())), handler);
}