XMLPullParserではなくSAXを使用すると、より適切で効率的な出力が見つかりました...私のシナリオは、XMLタグの下の属性を解析することです。これを簡単に実行して、データベースにスムーズに挿入できます...状況によって異なります。 XMLファイルに書き込む必要があります。DOMパーサーが好きです。
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
currentElement = true;
db = new DatabaseHelper(thecontext);
if (qName.equals("Asa.Amms.Data.Entity.User")) {
int length = attributes.getLength();
for (int i = 0; i < length; i++) {
String name = attributes.getQName(i);
if (name.equals("Id")) {
id = Integer.parseInt(attributes.getValue(i));
}
if (name.equals("Login")) {
LoginID = attributes.getValue(i).toString();
}
if (name.equals("Name")) {
Name = attributes.getValue(i).toString();
}
if (name.equals("Password")) {
Password = attributes.getValue(i).toString();
}
if (name.equals("ProgramOfficerId")) {
user_ProgramOfficerId = Integer.parseInt(attributes.getValue(i).toString());
}
}
Log.i("Baal dhukbe", id + LoginID + Name + Password);
db.insertUser(id, LoginID, Name, Password, user_ProgramOfficerId);
}
}