Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

java - Exporting a SQLite database to an XML file in Android

I know this is possible but I'm not really sure where to start. Has anyone been able to achieve this?

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The DataXmlExporter class described in this article will export a SQL lite DB to an XML file.

http://www.screaming-penguin.com/node/7749

The full example is available in this SVN repo. The ManageData class invokes the export.

http://totsp.com/svn/repo/AndroidExamples/trunk/

You will need to create an application class that exposes the DB and referenced as the application name in the AndroidManifest.xml file. Then use that DB as the argument to the DataXmlExporter constructor.

Here's the application class I use. You should already have a class (probably not named DatabaseHelper) that extends SQLiteOpenHelper

package com.billybobbain.android.someapp;
import android.app.Application;
import android.util.Log;

public class MyApplication extends Application {

   public static final String APP_NAME = "SomeApp";  

   private DatabaseHelper dataHelper;   

   @Override
   public void onCreate() {
      super.onCreate();
      Log.d(APP_NAME, "APPLICATION onCreate");
      this.dataHelper = new DatabaseHelper(this);      
   }

   @Override
   public void onTerminate() {
      Log.d(APP_NAME, "APPLICATION onTerminate");      
      super.onTerminate();      
   }

   public DatabaseHelper getDataHelper() {
      return this.dataHelper;
   }

   public void setDataHelper(DatabaseHelper dataHelper) {
      this.dataHelper = dataHelper;
   }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...