Quick Start
   Description   NEW!
   Project at SF.net
   ToDo List   NEW!

   SourceForge.net Logo

   javaNet.net Logo


Quick Start Example

Simple example:  We have some XML document, let it be simple XML-file (see below) and need to change telephone to "800-333-3333" for employee with lastname= "Doe" in the file employees.xml (see below):

<employee id="123">
<employee id="456">

XTAS Solution: the PhoneModifier.java:

import xtas.*;
public class PhoneModifier
     public void modify(String lastName, String newPhone) throws Exception
       try {
             String xPath = "/employees/employee[lastname='"+lastName+"']/telephone/text()";
             Statement qc = new SimpleStatement(QueryType.UPDATE, 
                                                                            "employees.xml", "employees.xml");
              Query q = new Query( qc );
        }  catch ( Exception e)  {
             throw new Exception("Error occured: "+e);
      public static void main(String[] args) throws Exception {
          new PhoneModifier().modify( "Doe", "800-333-3333");

Method PhoneModifier.modify(..) includes:

  • building of XPath expression for the querying old value of telephone element for employee with lastname "Doe"
  • creatng of XTAS UPDATE Query with this xpath expression, new value of telephone number, query data source (local file "employees.xml") and query data destination (local file "employees.xml")
  • execution of this query that will select old telephone by this XPath expression and update with new one
  • storing (serialize()) query's result in the local file "employees.xml"

You can check out the result in the employees.xml but note that for building executable you need the xtas.jar, so your building string must looks like: javac -classpath ../dist/xtas.jar PhoneModifier.java

and in run time your need (besides the xtas.jar) the xml-apis library, parser (Xerces 2) and XSLT-implementation (Xalan 2), so your run string must looks like: java -classpath .;../lib/xalan.jar;../lib/xml-apis.jar;../lib/xercesImpl.jar;../dist/xtas.jar PhoneModifier

and in the 5-th line of employees.xml you will see: <telephone>800-333-3333 </telephone>