XML的QL查询语言及其实现

1.      XML-QL查询实现途径

通过研究分析AT&T的查询引擎,可知XML-QL查询实现结构如下图:XML-QL查询的数据源是XML数据集,其他具有一定数据结构的数据文档、数据库等数据源通过转化成XML文档,也构成XML-QL的查询数据源。要实现XML-QL查询,需要开发一个XML-QL编译器(查询引擎),并根据查询需要编写包含QL查询语句的查询文件。编译器通过对查询文件的语法和词法结构进行分析,对XML数据源文档进行解析,最终得到我们需要的数据,并以XML(或HTML)文档的格式输出。

为了说明问题,我们利用AT&T的查询引擎来运行我们自己编写的查询文件。工作流程解释如下:

首先构建bookdata.xml文档和bookprice.xml文档作为查询数据源,第一个文档含有图书信息,第二个文档含有图书价格信息。

然后根据查询要求编写了两个XML-QL查询文件。一个是Seach.xmlql,要求查询出版社为“高等教育出版社”的图书信息。一个是Joinquery.xmlql,将bookdata.xmlbookprice.xml文档中的作者、书籍名称和价格信息实现连接。

最后通过运行查询引擎将XML源文档和XML-QL查询文件结合形成我们关心的XML数据。

bookdata.xml文档内容如下:

<?xml version="1.0" encoding="gb2312"?>

<?xml-stylesheet type="text/xsl" href="bookdata.xsl" ?>

<lib>

       <book year="2000">

              <title>数据库系统概论</title>

              <author><lastname>萨师煊 王珊</lastname></author>

              <publisher><name>高等教育出版社</name></publisher>

       </book>

       <book year="2001">

              <title>C程序设计第二版</title>

              <author><lastname>谭浩强</lastname></author>

              <publisher><name>清华大学出版社</name></publisher>

       </book>

       <book year="2002">

              <title>编译原理</title>

              <author><lastname>陈火旺</lastname></author>

              <publisher><name>国防工业出版社</name></publisher>

       </book>       <book year="2002">

              <title>高等数学</title>

              <author><lastname>陈天德</lastname></author>

              <publisher><name>山东大学出版社</name></publisher>

       </book>       <book year="2000">

              <title>管理学</title>

              <author><lastname>周三多</lastname></author>

              <publisher><name>高等教育出版社</name></publisher>

       </book>

</lib>

bookprice.xml内容如下:

<?xml version="1.0" encoding="gb2312"?>

<bookprice>

       <book>

              <title>C程序设计第二版</title>

              <price>$20.50</price>

       </book>

       <book>

              <title>编译原理</title>

              <price>$10.00</price>

       </book>

       <book>

              <title>高等数学</title>

              <price>$5.60</price>

       </book>

       <book>

              <title>管理学</title>

              <price>$10.30</price>

       </book>

</bookprice>

查询文档search.xmlql程序清单:

function query()

{

construct <title>$title</title>

where    <lib.book>

              <title>$title</title>

              <publisher><name>”高等教育出版社"</name></publisher>

              </lib.book>  IN "bookdata.xml"

}

查询文档joinquery.xmlql程序清单:

function joinquery()

{

       construct <result>

       {

              construct <book>

                                   <title>$title</title>

                                   <author>$author</author>

                                   <price>$price</price>

                              </book>

              where <lib>

                            <book>

                                   <title.PCDATA>$title</title.PCDATA>

                                   <author>$author</author>

                            </book>

                       </lib> IN "bookdata.xml"

                       <bookprice>

                          <book>

                                   <title.PCDATA>$title</title.PCDATA>

                                   <price>$price</price>

                            </book>

                       </bookprice> IN "bookprice.xml"

       }</result>

}

 

2.      结束语

上述分析结果表明,作为Web环境中组织数据的一种方式,HTML描述了显示全球数据的通用方法,而XML提供了直接处理全球数据的通用方法。XML使用一个简单而有灵活的标准格式,为基于Web的应用提供了一个描述数据和交换数据的有效手段。而XML-QL作为目前比较高效的查询XML文档的语言表现出很强的实用性。

posted on 2004-07-01 17:20  李想  阅读(1061)  评论(0编辑  收藏  举报

导航