导出一个SQLite数据库在Android的XML文件 [英] Exporting a SQLite database to an XML file in Android

查看:151
本文介绍了导出一个SQLite数据库在Android的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

这篇关于导出一个SQLite数据库在Android的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆