Xindice随笔

FuqiangWang


2014年从msn space存档中重新恢复出来!

作为本地xml数据库的一种,xindice遵循XML:DB API标准,给出了相当于Core Level 1水平的API功能实现。XML:DB API之相对于NXD(Native XML Database)来说,就相当于JDBC之相当于RDBMS。

通过xindice,我们可以通过他来保存xml文档数据,通过其提供的各种服务来对文档数据进行管理。其中,我们可以通过XPathQueryService服务来查询xml数据库中的xml文档数据,通过XUpdateQueryService服务来对xml进行更新,等等。

下面只是简单罗列一些XUpdateQueryService提供的XUpdate命令,处于时间考虑,如果有时间,可以写一些有关xindice本地xml数据库的更详细的文档,另外,developerworks网站有一篇说明xindice的介绍性质的文章,如要参考,可以search一下(在xml section)。

            [b]XUpdate Commands[/b]
            xupdate:insert-before Inserts a new node in document order before the selected node
            xupdate:insert-after Inserts a new node in document order after the selected node
            xupdate:update Replaces all child nodes of the selected node with the specified nodes
            xupdate:append Appends the specified node to the content of the selected node
            xupdate:remove Remove the selected node
            xupdate:rename Renames the selected node
            xupdate:variable Defines a variable containing a node list that can be reused in later operations

            [b]XUpdate Node Construction [/b] 
            xupdate:element Creates a new element in the document
            xupdate:attribute Creates a new attribute node associated with an xupdate:element
            xupdate:text Creates a text content node in the document
            xupdate:processing-instruction Creates a processing instruction node in the document
            xupdate:comment Creates a new comment node in the document
            

下面是xindice提供的文档中给出的一个简单的XUpdate命令实例:

Basic XUpdate Insert Command
            
            <xupdate:modifications version="1.0"
                    xmlns:xupdate="http://www.xmldb.org/xupdate">
               <xupdate:insert-after select="/addresses/address[1]" >
                  
                  <xupdate:element name="address">
                     <xupdate:attribute name="id">2</xupdate:attribute>
                     <fullname>John Smith</fullname>
                     <born day=''2'' month=''12'' year=''1974''/>
                     <country>Germany</country>
                 </xupdate:element>
               </xupdate:insert-after>
            </xupdate:modifications>

在程序中,可以通过以下类似代码调用该XUpdate命令对文档进行更新:

String xupdate = 刚才的XUpdate命令内容;
            XUpdateQueryService service =(XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
            service.update(xupdate);
            ...
            //其他操作,比如释放资源

因为更新命令中包括了insert,delete和update等功能,所以,其他的管理可以以上面类似的形式实现,通过为XUpdateQueryService提供相应的XUpdate命令就可以了。 至于查询操作,步骤类似,只要从Collection中取得XPathQueryService服务,然后为其指定查询用的Xpath表达式,最后对结果(Resource)进行处理。

Xindice发布包中附带有一个AddressBook应用,以用来掩饰基于Xindice的web应用实现模型,但其提供的Ant编译脚本有问题,没有指定编译时候的classpath,所以,在现在的机器上不能编译成功,最后,通过为该脚本添加了以下内容才使编译通过:

即在build.xml文件开始添加

<path  id="project.classpath">
               <fileset dir="E:\APIs">
                 <include name="**/*.jar"/>
               </fileset>  
               <fileset dir="E:\xindice\java\lib">
                 <include name="**/*.jar"/>
               </fileset>   
             </path>

然后在compile目标的javac任务中为其指定classpathref为project.classpath即可,编译完成后生成Addressbook.war文件,可以部署到App Server(我部署在resin2.1.1 App服务器上)。 稍后会考虑使用struts对该Webapp进行重构,因为相对于现在基于Command模式实现的实例,struts能更清晰的表达控制流程。


>>>>>> 更多阅读 <<<<<<

「为AI疯狂」星球上,扶墙老师正在和朋友们讨论有趣的AI话题,你要不要⼀起来呀?^-^
这里

  1. 不但有及时新鲜的AI资讯和深度探讨
  2. 还分享AI工具、产品方法和商业机会
  3. 更有体系化精品付费内容等着你,加入星球(https://t.zsxq.com/0dI3ZA0sL) 即可免费领取。(加入之后一定记得看置顶消息呀!)

知识星球二维码

存量的时代,省钱就是赚钱。
在增量的时代,省钱其实是亏钱。
避坑儿是省钱的一种形式,更是真正聪明人的选择!
弯路虽然也是路,但还是能少走就少走,背后都是高昂的试错成本。
订阅「福报」,少踩坑,少走弯路,多走一步,就是不一样的胜率!

订阅「福报Premium订阅」