Example usage for javax.xml.parsers SAXParser getXMLReader

List of usage examples for javax.xml.parsers SAXParser getXMLReader

Introduction

In this page you can find the example usage for javax.xml.parsers SAXParser getXMLReader.

Prototype


public abstract org.xml.sax.XMLReader getXMLReader() throws SAXException;

Source Link

Document

Returns the org.xml.sax.XMLReader that is encapsulated by the implementation of this class.

Usage

From source file:MyErrorHandler.java

static public void main(String[] arg) throws Exception {
    boolean validate = false;
    validate = true;/*from  w w w.j  a  va  2  s . c om*/

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(validate);

    XMLReader reader = null;
    SAXParser parser = spf.newSAXParser();
    reader = parser.getXMLReader();

    reader.setErrorHandler(new MyErrorHandler());
    reader.parse("http://yourURL/TextDoc3.xml");
}

From source file:MyErrorHandler.java

static public void main(String[] arg) throws Exception {
    boolean validate = false;
    validate = true;//from  ww w . j a  va  2 s .co  m

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(validate);

    XMLReader reader = null;
    SAXParser parser = spf.newSAXParser();
    reader = parser.getXMLReader();

    reader.setErrorHandler(new MyErrorHandler());
    InputSource is = new InputSource("test.xml");
    reader.parse(is);
}

From source file:MainClass.java

static public void main(String[] arg) throws Exception {
    boolean validate = false;

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(validate);//from   w  w w .  j a v  a2  s  .c  o m

    XMLReader reader = null;
    SAXParser parser = spf.newSAXParser();
    reader = parser.getXMLReader();

    reader.setErrorHandler(new MyErrorHandler());
    reader.parse(new InputSource(new StringReader(xmlString)));
}

From source file:XMLTransform.java

public static void main(String[] args) throws Exception {
    System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");
    SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
    XMLReader reader = parser.getXMLReader();
    TransformerFactory factory = TransformerFactory.newInstance();
    System.out.println(factory);/*w  ww .java 2  s .  co m*/
    Transformer transformer = factory.newTransformer(new StreamSource("./xsl/books-sql.xsl"));
    transformer.setParameter("user", "root");
    transformer.setParameter("password", "123456");
    transformer.transform(new StreamSource("./xml/books.xml"), new StreamResult(System.out));
}

From source file:MyErrorHandler.java

static public void main(String[] arg) throws Exception {
    boolean validate = false;
    validate = true;//from   w  ww.j av a2 s . c om

    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(validate);

    XMLReader reader = null;
    SAXParser parser = spf.newSAXParser();
    reader = parser.getXMLReader();

    reader.setErrorHandler(new MyErrorHandler());
    InputSource is = new InputSource(new StringReader(getXMLData()));
    reader.parse(is);
}

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:SAXCheck.java

static public void main(String[] arg) {
    String filename = null;//from w ww .j  a v a  2  s .  c  om
    boolean validate = false;

    if (arg.length == 1) {
        filename = arg[0];
    } else if (arg.length == 2) {
        if (!arg[0].equals("-v"))
            usage();
        validate = true;
        filename = arg[1];
    } else {
        usage();
    }

    // Create a new factory to create parsers that will
    // validate or not, according to the flag setting.
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setValidating(validate);

    // Create the XMLReader to be used to check for errors.
    XMLReader reader = null;
    try {
        SAXParser parser = spf.newSAXParser();
        reader = parser.getXMLReader();
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }

    // Install an error handler in the reader.
    reader.setErrorHandler(new MyErrorHandler());
    // Use the XMLReader to parse the entire file.
    try {
        InputSource is = new InputSource(filename);
        reader.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }
}

From source file:SAXCopy.java

static public void main(String[] arg) {
    try {//from   w  w w. j a va 2  s . c om
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser parser = spf.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        reader.setErrorHandler(new MyErrorHandler());
        MyCopyHandler duper = new MyCopyHandler();
        reader.setContentHandler(duper);
        InputSource is = new InputSource("test.xml");
        reader.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (ParserConfigurationException e) {
        System.err.println(e);
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }
}

From source file:MyContentHandler.java

static public void main(String[] arg) {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader reader = null;// www  .  j  av a 2s .  c o  m
    try {
        SAXParser parser = spf.newSAXParser();
        reader = parser.getXMLReader();
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }

    reader.setErrorHandler(new MyErrorHandler());
    reader.setContentHandler(new MyContentHandler());

    try {
        InputSource is = new InputSource(new StringReader(getXMLData()));
        reader.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }
}

From source file:MyContentHandler.java

static public void main(String[] arg) {
    SAXParserFactory spf = SAXParserFactory.newInstance();
    XMLReader reader = null;//  ww  w . ja  v  a  2s  . c  om
    try {
        SAXParser parser = spf.newSAXParser();
        reader = parser.getXMLReader();
    } catch (Exception e) {
        System.err.println(e);
        System.exit(1);
    }

    reader.setErrorHandler(new MyErrorHandler());
    reader.setContentHandler(new MyContentHandler());

    try {
        InputSource is = new InputSource("test.xml");
        reader.parse(is);
    } catch (SAXException e) {
        System.exit(1);
    } catch (IOException e) {
        System.err.println(e);
        System.exit(1);
    }
}