basex - XML数据库 浅谈

BaseX 是一个开源的XML数据库,用来存储紧缩的XML数据,提供了高效的 XPath 和 XQuery 的实现,还包括一个前端操作界面。用java编写!

本人做了简单的汉化后的版本截图

 

先介绍下关于BaseX的一些资源:

BaseX官方地址:http://basex.org/

BaseX安装包下载地址:http://basex.org/products/download/

BaseX源码包下载地址:http://ftp.de.debian.org/debian/pool/main/b/basex/basex_7.3.orig.tar.gz

       (注:这个源码包不在官网上下载而是连接到一个叫“Debian” 源码资源站,一个很不错的源码资源站,可以很好的导入到Eclipse里。地址:http://packages.debian.org/squeeze/。但是这个源码包下载链接地址可以在官网找到:http://basex.org/products/download/页面里选“Debian GNU”-->http://packages.debian.org/sid/basex在此页面选页面右面的“源码下载包”)

BaseX应用实例下载地址:http://docs.basex.org/wiki/Main_Page 选“Developer Section”-->“java Exaples”-->" basex-examples "-->" Downloads " --> " Download as zip "即可下载

 

功能介绍:

basex  ..........  Standalone local XML database. Command line interface.
basexgui  .......  Standalone local XML database. Graphical user interface.
basexserver  ....  BaseX XML Database Server.
basexclient  ....  BaseX XML Database Client.

 

多看下“BaseX应用实例”能对BaseX使用有所帮助,里面告诉你怎么连接,使用BaseX(注意:在运行BaseX应用实例时要将basexserver服务开开。)

摘取其中一段链接,查询的代码:

try {
      // create session
      final BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin");

      try {
        // define input stream
        final InputStream bais =
          new ByteArrayInputStream("<xml>Hello World!</xml>".getBytes());

        // create new database
        session.create("database", bais);
        System.out.println(session.info());

        // run query on database
        System.out.println(session.execute("xquery doc('database')"));

        // drop database
        session.execute("drop db database");

      } catch(final IOException ex) {
        // print exception
        ex.printStackTrace();
      }

      // close session
      session.close();

    } catch(final IOException ex) {
      // print exception
      ex.printStackTrace();
    }

 

—————————————————————————————————————————————————————————————————————————————

下面是我在项目里的需求,跟BaseX理解与使用没有关系,职位学习BaseX可以绕道。

由于项目的需求需要将BaseXGUI嵌到浏览器里,我用了applet技术

 

修改org.basex.gui类:

1,setVisible(true);将此句话注释掉才能在浏览器里显示,这个话的意思是显示到GUI里

2,//增加此代码

  public BaseXBack getTop() {
    return top;
  }

 

创建applet类:

public class BaseXApplet extends JApplet{
 
  /** Database context. */
  final Context context = new Context();
  /** Files, specified as arguments. */
  final StringList files = new StringList();
  /** Mac OS X GUI optimizations. */
  GUIMacOSX osxGUI;

  @Override
  public void init() {
    // TODO Auto-generated method stub
    super.init();
    //JLabel label = new JLabel("hello",SwingConstants.CENTER);
   
 // read properties
    final GUIProp gprop = new GUIProp();
    // cache results to pass them on to all visualizations
    context.prop.set(Prop.CACHEQUERY, true);
    // reduce number of results to save memory
    context.prop.set(Prop.MAXHITS, gprop.num(GUIProp.MAXHITS));
    // initialize fonts and colors
    GUIConstants.init(gprop);
   
    final GUI gui = new GUI(context, gprop);
    add(gui.getTop());
  }
 
}

 

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值