我想将来自Web服务的XML结果数组插入到我的android sqlite数据库中以生成列表视图,如何从Web服务获取此字符串数组并通过调用Web服务插入到sqlite DB中,下面是我的代码详情。
XML结果:
<ArrayOfUser xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<User>
<from_mobileno>4359835745</from_mobileno>
<to_mobileno>6757575</to_mobileno>
<to_contactname>xxxx</to_contactname>
<priority1>1</priority1>
<priority2>0</priority2>
<priority3>0</priority3>
<panic_type>Indoor</panic_type>
<status>A</status>
</User>
<User>
<from_mobileno>+4359835745</from_mobileno>
<to_mobileno>3634653</to_mobileno>
<to_contactname>yyyy</to_contactname>
<priority1>1</priority1>
<priority2>2</priority2>
<priority3>0</priority3>
<panic_type>Outdoor</panic_type>
<status>A</status>
</User>
</ArrayOfUser>
Sqlite DB:
public class RegisterConactDBAdapter {
SQLiteOpenHelper dbhelper;
SQLiteDatabase database;
String LOGTAG="RegisterContactDBAdapter";
static final String REGCONTACT_TABLE="regcontact";
private static final String SNO="si_no";
private static final String FROMMOBILENO="from_mobileno";
private static final String CONTACTNAME="contact_name";
private static final String TOMOBILENO="to_mobileno";
private static final String PRIORITY1="priority1";
private static final String PRIORITY2="priority2";
private static final String PRIORITY3="priority3";
private static final String PANICTYPE="panic_type";
private static final String STATUS="status";
private static final String[] allColumns={
SNO,
FROMMOBILENO,
CONTACTNAME,
TOMOBILENO,
PRIORITY1,
PRIORITY2,
PRIORITY3,
PANICTYPE,
STATUS
};
public static String createRegisterContactTable(){
String CREATE_REGCONTACTTABLE="CREATE TABLE " + REGCONTACT_TABLE + "("
+ SNO+ " INTEGER PRIMARY KEY AUTOINCREMENT" + ","
+ FROMMOBILENO+ " TEXT" + ","
+ CONTACTNAME+ " TEXT" + ","
+ TOMOBILENO+ " TEXT" + ","
+ PRIORITY1+ " TEXT" + ","
+ PRIORITY2+ " TEXT" + ","
+ PRIORITY3+ " TEXT" + ","
+ PANICTYPE+ " TEXT" + ","
+ STATUS+" TEXT" +
")";
return CREATE_REGCONTACTTABLE;
}
public RegisterConactDBAdapter(Context context){
Log.i(LOGTAG,"RegisterConactDBAdapter...");
dbhelper= new DBHandler(context);
}
public void open(){
database = dbhelper.getWritableDatabase();
Log.i(LOGTAG,"Database Opened");
}
public void close(){
dbhelper.close();
Log.i(LOGTAG,"Database Closed");
}
public void CreateUser(Contact contact){
ContentValues values= new ContentValues();
values.put(FROMMOBILENO,contact.getFromMobileno());
values.put(CONTACTNAME,contact.getContactName());
values.put(TOMOBILENO,contact.getToMobileno());
values.put(PRIORITY1,contact.getPriority1());
values.put(PRIORITY2,contact.getPriority2());
values.put(PRIORITY3,contact.getPriority3());
values.put(PANICTYPE, contact.getPanicType());
values.put(STATUS,contact.getStatus());
Log.i("Fisrt Row Id...",SNO);
database.insert(REGCONTACT_TABLE, null, values);
}
}