Search in sources :

Example 6 with XMLReader

use of org.xml.sax.XMLReader in project android_frameworks_base by ParanoidAndroid.

the class Xml method parse.

/**
     * Parses xml from the given input stream and fires events on the given SAX
     * handler.
     */
public static void parse(InputStream in, Encoding encoding, ContentHandler contentHandler) throws IOException, SAXException {
    XMLReader reader = new ExpatReader();
    reader.setContentHandler(contentHandler);
    InputSource source = new InputSource(in);
    source.setEncoding(encoding.expatName);
    reader.parse(source);
}
Also used : InputSource(org.xml.sax.InputSource) ExpatReader(org.apache.harmony.xml.ExpatReader) XMLReader(org.xml.sax.XMLReader)

Example 7 with XMLReader

use of org.xml.sax.XMLReader in project android_frameworks_base by ParanoidAndroid.

the class Xml method parse.

/**
     * Parses the given xml string and fires events on the given SAX handler.
     */
public static void parse(String xml, ContentHandler contentHandler) throws SAXException {
    try {
        XMLReader reader = new ExpatReader();
        reader.setContentHandler(contentHandler);
        reader.parse(new InputSource(new StringReader(xml)));
    } catch (IOException e) {
        throw new AssertionError(e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) ExpatReader(org.apache.harmony.xml.ExpatReader) StringReader(java.io.StringReader) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 8 with XMLReader

use of org.xml.sax.XMLReader in project jmonkeyengine by jMonkeyEngine.

the class SceneMaterialLoader method load.

public MaterialList load(AssetManager assetManager, String folderName, InputStream in) throws IOException {
    try {
        this.assetManager = assetManager;
        this.folderName = folderName;
        reset();
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XMLReader xr = factory.newSAXParser().getXMLReader();
        xr.setContentHandler(this);
        xr.setErrorHandler(this);
        InputStreamReader r = null;
        try {
            r = new InputStreamReader(in);
            xr.parse(new InputSource(r));
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return materialList;
    } catch (SAXException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    } catch (ParserConfigurationException ex) {
        IOException ioEx = new IOException("Error while parsing Ogre3D dotScene");
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

Example 9 with XMLReader

use of org.xml.sax.XMLReader in project OpenNotebook by jaltekruse.

the class OldReader method readFile.

public Document readFile(InputStreamReader file) throws SAXException, IOException {
    attributeNameInError = null;
    attributeValueInError = null;
    objectWithError = null;
    XMLReader reader = XMLReaderFactory.createXMLReader();
    reader.setContentHandler(this);
    reader.setErrorHandler(this);
    reader.parse(new InputSource(file));
    if (doc == null) {
        if (DEBUG) {
            System.out.println("error 1");
        }
        throw new IOException("improper document format");
    }
    if (hadAttributeError) {
        if (DEBUG) {
            System.out.println("error 2");
        }
        throw new IOException("improper document format, error with attribute '" + attributeNameInError + "' with a value of '" + attributeValueInError + "'" + " in object '" + objectWithError + "'");
    }
    return doc;
}
Also used : InputSource(org.xml.sax.InputSource) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader)

Example 10 with XMLReader

use of org.xml.sax.XMLReader in project musicbrainz-android by jdamcd.

the class ResponseParser method parse.

protected void parse(InputStream stream, DefaultHandler handler) throws IOException {
    try {
        SAXParser parser = factory.newSAXParser();
        XMLReader reader = parser.getXMLReader();
        InputSource source = new InputSource(stream);
        reader.setContentHandler(handler);
        reader.parse(source);
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParser(javax.xml.parsers.SAXParser) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Aggregations

XMLReader (org.xml.sax.XMLReader)196 InputSource (org.xml.sax.InputSource)160 SAXException (org.xml.sax.SAXException)66 IOException (java.io.IOException)65 SAXSource (javax.xml.transform.sax.SAXSource)38 SAXParserFactory (javax.xml.parsers.SAXParserFactory)37 SAXParser (javax.xml.parsers.SAXParser)36 StringReader (java.io.StringReader)35 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)28 ExpatReader (org.apache.harmony.xml.ExpatReader)24 InputStream (java.io.InputStream)20 ContentHandler (org.xml.sax.ContentHandler)20 TransformerException (javax.xml.transform.TransformerException)17 DOMSource (javax.xml.transform.dom.DOMSource)15 StreamSource (javax.xml.transform.stream.StreamSource)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStreamReader (java.io.InputStreamReader)9 Source (javax.xml.transform.Source)9 Transformer (javax.xml.transform.Transformer)9 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)9