Class Translator


public class Translator
extends Object

Creates xml documents. The xpaths and it's value is translated into nodes in the xml document. Facade for the translet package. For most common usage, this class and it's helper classes ( DataIterator, XPathExpr, DOMTranslatorResult ) are the only APIs that needs to be known. See Example below.

XPath models an XML document as a tree of nodes. The basic XPath syntax is similar to filesystem addressing.

Since XPath to an xml document branch is not usually a one-to-one mapping, certain assumptions are made about the XPath to create a unique branch. Also, only a part of the Xpath specification is implemented, and an expception may be thrown if an unsupported XPath expression is encountered.

Some examples of supported xpaths are are:

Some examples of unsupported xpaths are:

Example Usage:

import org.w3c.dom.Document; import org.translet.processor.Translator; import org.translet.processor.DataIterator; import org.translet.processor.XPathExpr; import org.translet.processor.dom.DOMTranslatorResult; .... .... // setup the data. List is needed to maintain the order. List xpaths = Arrays.asList(new XPathExpr[] { new XPathExpr("/a/b","some data"), new XPathExpr("/a/b/@id","1"), new XPathExpr("/a/b[2]","more data"), new XPathExpr("/a/b[2]/@id","2") }); final Iterator it = xpaths.iterator(); // Create the adaptor instance. DataIterator dit = new DataIterator() { public boolean hasNext() { return it.hasNext(); } public XPathExpr nextXPath() { return (XPathExpr); } }; DOMTranslatorResult result = new DOMTranslatorResult(); Translator.getInstance().translate(dit,result); Document doc = result.getDocument(); // will give you the dom document. .... ....

Karthikeyan Mariappan.

Method Summary
static Translator getInstance()
          Obtains an instance of the translator.
 void translate(DataIterator xIterator, TranslatorResult result)
          Translates the collection of xpaths into xml document.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Method Detail


public static Translator getInstance()
Obtains an instance of the translator.
Translator an instance of the translator.


public void translate(DataIterator xIterator,
                      TranslatorResult result)
               throws ProcessException
Translates the collection of xpaths into xml document.
xIterator - iterator over the xpaths and it's values.
result - holds information about how the output will be held.