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;
}
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));
}
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);
}
}
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());
}
}
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;
}
}
Aggregations