导出一个SQLite数据库在Android的XML文件数据库、文件、SQLite、XML

由网友(刀尖萝莉)分享简介:我知道这是可能的,但我真的不知道从哪里开始。有没有人能够做到这一点?I know this is possible but I'm not really sure where to start. Has anyone been able to achieve this?感谢。推荐答案在这篇文章中所描述的 Dat...

我知道这是可能的,但我真的不知道从哪里开始。有没有人能够做到这一点?

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

感谢。

推荐答案

在这篇文章中所描述的 DataXmlExporter 类将一个SQL精简版数据库导出到一个XML文件中。

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

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

完整的示例,可以在这个SVN回购。该 ManageData 类调用的出口。

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

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

您将需要创建一个公开的数据库,并在AndroidManifest.xml文件的应用程序名称引用的应用程序类。然后使用该数据库作为参数传递给 DataXmlExporter 的构造。

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.

下面是我使用的应用程序类。你应该已经有一个类(可能没有名为 DatabaseHelper ),扩展 SQLiteOpenHelper

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;
   }
}