use of org.xmlpull.v1.XmlPullParserFactory in project freeline by alibaba.
the class GradleDependencyEntity method parse.
/**
* xml解析为对象
*
* @param text
* @return
*/
public static GradleDependencyEntity parse(String text) {
GradleDependencyEntity entity = new GradleDependencyEntity();
XmlPullParserFactory f = null;
try {
f = XmlPullParserFactory.newInstance();
f.setNamespaceAware(true);
XmlPullParser xmlPullParser = f.newPullParser();
xmlPullParser.setInput(new InputStreamReader(new ByteArrayInputStream(text.getBytes())));
int eventType = xmlPullParser.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
} else if (eventType == XmlPullParser.START_TAG) {
String name = xmlPullParser.getName();
if (name.equals("groupId")) {
entity.setGroupId(xmlPullParser.nextText());
} else if (name.equals("artifactId")) {
entity.setArtifactId(xmlPullParser.nextText());
} else if (name.equals("version")) {
String version = xmlPullParser.nextText();
entity.setVersion(version);
} else if (name.equals("lastUpdated")) {
entity.setUpdateTime(xmlPullParser.nextText());
}
} else if (eventType == XmlPullParser.END_TAG) {
} else if (eventType == XmlPullParser.TEXT) {
}
eventType = xmlPullParser.next();
}
} catch (Exception e) {
e.printStackTrace();
}
return entity;
}
use of org.xmlpull.v1.XmlPullParserFactory in project android-maps-utils by googlemaps.
the class KmlParserTest method createParser.
public XmlPullParser createParser(int res) throws Exception {
InputStream stream = getInstrumentation().getContext().getResources().openRawResource(res);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
parser.setInput(stream, null);
parser.next();
return parser;
}
use of org.xmlpull.v1.XmlPullParserFactory in project android_frameworks_base by DirtyUnicorns.
the class DaylightHeaderProvider method loadHeaders.
private void loadHeaders() throws XmlPullParserException, IOException {
mHeadersList = new ArrayList<DaylightHeaderInfo>();
InputStream in = null;
XmlPullParser parser = null;
try {
if (mHeaderName == null) {
in = mRes.getAssets().open("daylight_header.xml");
} else {
int idx = mHeaderName.lastIndexOf(".");
String headerConfigFile = mHeaderName.substring(idx + 1) + ".xml";
in = mRes.getAssets().open(headerConfigFile);
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setInput(in, "UTF-8");
loadResourcesFromXmlParser(parser);
} finally {
// Cleanup resources
if (parser instanceof XmlResourceParser) {
((XmlResourceParser) parser).close();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
use of org.xmlpull.v1.XmlPullParserFactory in project android_frameworks_base by AOSPA.
the class TtmlRenderingWidget method loadParser.
private void loadParser(String ttmlFragment) throws XmlPullParserException {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
mParser = factory.newPullParser();
StringReader in = new StringReader(ttmlFragment);
mParser.setInput(in);
}
use of org.xmlpull.v1.XmlPullParserFactory in project android_frameworks_base by ResurrectionRemix.
the class DaylightHeaderProvider method loadHeaders.
private void loadHeaders() throws XmlPullParserException, IOException {
mHeadersList = new ArrayList<DaylightHeaderInfo>();
InputStream in = null;
XmlPullParser parser = null;
try {
if (mHeaderName == null) {
if (DEBUG)
Log.i(TAG, "Load header pack config daylight_header.xml");
in = mRes.getAssets().open("daylight_header.xml");
} else {
int idx = mHeaderName.lastIndexOf(".");
String headerConfigFile = mHeaderName.substring(idx + 1) + ".xml";
if (DEBUG)
Log.i(TAG, "Load header pack config " + headerConfigFile);
in = mRes.getAssets().open(headerConfigFile);
}
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
parser = factory.newPullParser();
parser.setInput(in, "UTF-8");
loadResourcesFromXmlParser(parser);
} finally {
// Cleanup resources
if (parser instanceof XmlResourceParser) {
((XmlResourceParser) parser).close();
}
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
Aggregations