它在 eclipes 中的工作代码,但不了解 Intellij IDEA12
编写此代码以从资产中打开并获取 xml 或根据您的需要进行修改
try {
XmlPullParserFactory xppf = XmlPullParserFactory.newInstance();
XmlPullParser = xppf.newPullParser();
AssetManager manager = context.getResources().getAssets();
InputStream input = manager.open("createDb.xml");
xpp.setInput(input, null);
int type = xpp.getEventType();
while(type != XmlPullParser.END_DOCUMENT) {
if(type == XmlPullParser.START_DOCUMENT) {
Log.d(Tag, "In start document");
}
else if(type == XmlPullParser.START_TAG) {
Log.d(Tag, "In start tag = "+xpp.getName());
}
else if(type == XmlPullParser.END_TAG) {
Log.d(Tag, "In end tag = "+xpp.getName());
}
else if(type == XmlPullParser.TEXT) {
Log.d(Tag, "Have text = "+xpp.getText());
if(xpp.isWhitespace())
{
}
else
{
String strquery = xpp.getText();
db.execSQL(strquery);
}
}
type = xpp.next();
}
}
catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}