Search in sources :

Example 41 with XMLReader

use of org.xml.sax.XMLReader in project bilibili-android-client by HotBitmapGG.

the class BiliDanmukuParser method parse.

@Override
public Danmakus parse() {
    if (mDataSource != null) {
        AndroidFileSource source = (AndroidFileSource) mDataSource;
        try {
            XMLReader xmlReader = XMLReaderFactory.createXMLReader();
            XmlContentHandler contentHandler = new XmlContentHandler();
            xmlReader.setContentHandler(contentHandler);
            xmlReader.parse(new InputSource(source.data()));
            return contentHandler.getResult();
        } catch (SAXException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return null;
}
Also used : InputSource(org.xml.sax.InputSource) IOException(java.io.IOException) AndroidFileSource(master.flame.danmaku.danmaku.parser.android.AndroidFileSource) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Example 42 with XMLReader

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

the class Xml method parse.

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

Example 43 with XMLReader

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

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 44 with XMLReader

use of org.xml.sax.XMLReader in project jdk8u_jdk by JetBrains.

the class EntityScannerTest method main.

/**
     * main method.
     *
     * @param args Standard args.
     */
public static void main(String[] args) {
    try {
        StringBuilder builder = new StringBuilder();
        builder.append("<root attr=\"");
        for (int i = 0; i < 200; i++) {
            builder.append("\n");
        }
        builder.append("foo.");
        builder.append("\" />");
        final XMLReader reader = XMLReaderFactory.createXMLReader();
        System.out.println(reader.getClass().getName());
        reader.parse(new InputSource(new StringReader(builder.toString())));
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new RuntimeException("Test failed: ArrayIndexOutOfBoundsException " + e.getMessage());
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
}
Also used : InputSource(org.xml.sax.InputSource) XMLReader(org.xml.sax.XMLReader)

Example 45 with XMLReader

use of org.xml.sax.XMLReader in project jdk8u_jdk by JetBrains.

the class XMLKit method readFrom.

public static Element readFrom(Reader in, boolean tokenizing, boolean makeFrozen) throws IOException {
    Element sink = new Element();
    ContentHandler b = makeBuilder(sink.asList(), tokenizing, makeFrozen);
    XMLReader parser;
    try {
        parser = org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
    } catch (SAXException ee) {
        throw new Error(ee);
    }
    //parser.setFastStandalone(true);
    parser.setContentHandler(b);
    try {
        parser.setProperty("http://xml.org/sax/properties/lexical-handler", (LexicalHandler) b);
    } catch (SAXException ee) {
    // Ignore.  We will miss the comments and whitespace.
    }
    try {
        parser.parse(new InputSource(in));
    } catch (SAXParseException ee) {
        throw new RuntimeException("line " + ee.getLineNumber() + " col " + ee.getColumnNumber() + ": ", ee);
    } catch (SAXException ee) {
        throw new RuntimeException(ee);
    }
    switch(sink.size()) {
        case 0:
            return null;
        case 1:
            if (sink.get(0) instanceof Element) {
                return (Element) sink.get(0);
            }
        // fall through
        default:
            if (makeFrozen) {
                sink.shallowFreeze();
            }
            return sink;
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXParseException(org.xml.sax.SAXParseException) ContentHandler(org.xml.sax.ContentHandler) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

Aggregations

XMLReader (org.xml.sax.XMLReader)234 InputSource (org.xml.sax.InputSource)186 SAXException (org.xml.sax.SAXException)82 IOException (java.io.IOException)75 SAXParserFactory (javax.xml.parsers.SAXParserFactory)51 SAXSource (javax.xml.transform.sax.SAXSource)48 SAXParser (javax.xml.parsers.SAXParser)42 StringReader (java.io.StringReader)37 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)35 InputStream (java.io.InputStream)28 ExpatReader (org.apache.harmony.xml.ExpatReader)24 ContentHandler (org.xml.sax.ContentHandler)20 TransformerException (javax.xml.transform.TransformerException)19 DOMSource (javax.xml.transform.dom.DOMSource)18 StreamSource (javax.xml.transform.stream.StreamSource)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 FileReader (java.io.FileReader)16 InputStreamReader (java.io.InputStreamReader)12 SAXParseException (org.xml.sax.SAXParseException)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10