This Tutorial is available in PDF Book : How To Use XUpdate In Java With Xindice Database

The aim of this tutorial is to show you how to develop a simple java class that use CRUD (Create Read Update Delete ) operations with an xml file stored in a native XML Database.
firstly to begin you should download those tools:

  1. Launching the server and adding the XML file to the native database :

  2. let’s begin our project ,we should create a xml file for example called persons.xml in whish we add some person elements ,each person has different nodes(first name,last name,email ,age) this is an example of persons.xml :

    < persons >
    < person id=”1″ >
    < fname > FOUAD < /fname >
    < lname > SAIDY < /lname >
    < email > fouadsaidy@gmail.com < /email >
    < age > 22 < /age >
    < /person >

    < person id=”2″ >
    < fname > KEVIN < /fname >
    < lname > MITNICK < /lname >
    < email > kevin.mitnick@gmail.com < /email >
    < age > 45 < /age >
    < /person >

    < person id=”3″ >
    < fname > BILL < /fname >
    < lname > GATES < /lname >
    < email > bill.gates@gmail.com < /email >
    < age > 55 < /age >
    < /person >
    < /persons >

    We created the xml file let’s now store this file in Xindice database ,to do that we should start the server, open the Xindice Folder called xindice-1.0 –>launch startup.bat, to verify if the server is executed correctly open your navigator and show http://localhost:4080/ page if you saw an xindice page that means the server is launched without errors.

    The Server Is Running

    The Server Is Running

    Apache XIndice Start Page

    Apache XIndice Start Page

    Next step is to launch Xindice Browser which give us many options to look to the database (open XindiceBrowser and execute XIndiceBrowser.bat
    To add the Xml file to the XML database we should create a Collection in whish we will store this file:

    Create a Test Collection

    Create a Test Collection

    Now let’s add persons.xml file to the new collection :

    Add XML File To Test Collection

    Add XML File To Test Collection

    Add persons.xml to Test collection

    Add persons.xml to Test collection

    show persons.xml in XIndice Browser

    show persons.xml in XIndice Browser

    we finished the first step of configuration and insertion of XML file in native database,next step is to create a javaa classe wishes manipulate the XML file stored in the database.

  3. Update XML database in java

  4. open Eclipse Galileo IDE and create a new Java Project called test_xindice ,click the right mouse into the project and select Properties , in the properties window select Java Build Path –> Libraries , then click the Add External JARs… Button , select the 5 jar’s in the java–> lib folder (see the next image)

    Add Jars To Java Project

    Add Jars To Java Project


    show persons.xml in XIndice Browser

    show persons.xml in XIndice Browser

    classe called xupdate and add this code to your class :
    Download xupdate.java
    to execute this class we should modify the run configuration of the eclipse IDE to do that select in principal menu run–>run configuration–>Arguments , enter one of this arguments:

    • add a new person : -A persons farid safiri 25 farid@gmail.com
    • Remove the 4th person : -R persons 4
    • update the second person : -E persons 2 steve Mcarty 21 sMcarty@gmail.com

    after writhing one of those case in the argument section click run, you will see the xupdate code in the eclipse console, for example if we write the first option adding a new person to the persons.xml file stored in the database we will see the request like this :

    add Arguments to Eclipse run configuration

    add Arguments to Eclipse run configuration

    The code produced by the program and executed in the server :

    XUpdate code sent to the server

    XUpdate code sent to the server

    for more informations about how to use XUpdate UseCases

    now let’s see the modification in Xml database, move to XIndice Database Browser click the refresh button and select persons.xml file you will see that the forth person is added to the database :

    XML Database updated

    XML Database updated

    In the same way you can execute author options of removing or updating an element in the XML database .

  5. Execute XPath expression in java

  6. To learn XPath : XPath Tutorial

    create a simple java class called show_xml and copy this file to your class:
    show_xml.java
    execute this file and you will see the result in eclipse console like this :

    XPath Result

    XPath Result


    finally you achieved the mission of updating a XML Database and showing the XPath Result using java and Xindice Database, you can now create more complex application based on XML database .