Example Usage1:

import org.w3c.dom.Document; import org.translet.processor.Translator; import org.translet.processor.DataIterator; import org.translet.processor.XPathExpr; import org.translet.processor.ProcessException; import org.translet.processor.dom.DOMTranslatorResult; public class DataTranslator { .... ....     public void translate() throws ProcessException {
// setup the data. List is needed to maintain the order. List xpaths = Arrays.asList(new XPathExpr[] { new XPathExpr("/users/person[1]/name/firstname","Mike"), new XPathExpr("/users/person[2]/name/firstname","John"), new XPathExpr("/users/person[1]/name/lastname", "Jelks"), new XPathExpr("/users/person[2]/name/lastname", "Wayne"), new XPathExpr("/users/person[1]/name/@ssn","xxx-xx-xxxx"), new XPathExpr("/users/person[2]/name/@ssn","yyy-yy-yyyy") }); final Iterator it = xpaths.iterator(); // Create the adaptor instance. DataIterator dit = new DataIterator() { public boolean hasNext() { return it.hasNext(); } public XPathExpr nextXPath() { return (XPathExpr) it.next(); } };
// Actual code DOMTranslatorResult result = new DOMTranslatorResult(); Translator.getInstance().translate(dit,result); Document doc = result.getDocument(); // will give you the dom document.
   } //Method End .... .... }// Class End

Example Usage2:

Sample xml document created through a test case cancore_ex1.xml. For those interested, cancore_ex1.xml is a metadata xml example gotten from IMS XML Bindings web-site.

(The test case is part of junit test cases for the package in XPathProcessorTest.java)