VTDGen vg = new VTDGen(); if (vg.parseFile("c://xml//alex.txt", true)){ VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//L/D"); int i=-1; while((i=ap.evalXPath())!=-1){ long l = vn.getContentFragment(); System.out.println(" -==> "+ vn.toString((int )l, (int)(l>>32))); } }
String s = "<pn category=\"ONE\" GENERAL0=\"0\" GENERAL1=\"-1\" >previoustext</pn>"; vg.setDoc(s.getBytes()); vg.parse(true); vn = vg.getNav(); AutoPilot testAP = new AutoPilot(vn); testAP.selectXPath("/pn[@category]"); xm.bind(vn); int j; while((j = testAP.evalXPath()) != -1) { int p = vn.getText(); xm.updateToken(p, "new text"); } XMLByteOutputStream xbos =new XMLByteOutputStream(xm.getUpdatedDocumentSize()); xm.output(xbos); System.out.println(new String(xbos.getXML()));
protected boolean xPathExists(String xpath) throws XPathParseException, XPathEvalException, NavException { try { AutoPilot ap = getAutoPilot(xpath, vn); return ap.evalXPath() != -1; } finally { releaseAutoPilot(); } } }
/** * Moves the VTDNav cursor to the given XPath. * * @param xpath * The XPath to move to. * @return True if the XPath was found, false otherwise. * @throws XPathParseException * @throws XPathEvalException * @throws NavException */ protected boolean moveToXPath(String xpath) throws XPathParseException, XPathEvalException, NavException { AutoPilot ap = getAutoPilot(xpath, vn); int index = ap.evalXPath(); releaseAutoPilot(); return index != -1; }
public void readBinaryAttachment(HTTPInputStream input) throws VTDException, IOException{ // first read xml bytes into XMLBytes .... VTDGen vg = new VTDGen(); vg.setDoc(XMLBytes); vg.parse(false);// VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/ProcessRequest/BinaryAttachment/text()"); int i=0; while((i=ap.evalXPath())!=-1){ //i points to text node of String s = vn.toRawString(i); // you need to decode them } }
import com.ximpleware.*; public class simpleQuery { public static void main(String[] s) throws Exception{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", true)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//targetChannel/mnemonic/text()"); int i = ap.evalXPath(); if (i!=-1) System.out.println(" result ==>"+vn.toString(i)); } }
import com.ximpleware.*; public class accessName { public static void main(String[] args) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/param[@name='id']/text()"); int i=0; while((i=ap.evalXPath())!=-1){ System.out.println("text value "+vn.toString(i)); } } }
import com.ximpleware.*; public class extractValue{ public static void main(String s[]) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/aa/bb[name='k1']/value"); int i=0; while ((i=ap.evalXPath())!=-1){ System.out.println(" value ===>"+vn.toString(i)); } } }
import com.ximpleware.*; public class extractValue{ public static void main(String s[]) throws VTDException, IOException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/aa/bb[name='k1']/value"); int i=0; while ((i=ap.evalXPath())!=-1){ System.out.println(" value ===>"+vn.toString(i)); } } }
import com.ximpleware.*; public class xpathSearch { public static void main(String s[])throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("d:\\xml\\input.txt", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/base/parent/*/data[contains(.,'hey')]/../../@id"); int i; while ((i=ap.evalXPath())!=-1) System.out.println("attr id has the value of "+vn.toString(i+1)); } }
import com.ximpleware.*; public class removeElement { public static void main(String s[]) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/ClOrdIDS/ClOrdID[@id='3']"); int i=0; while((i=ap.evalXPath())!=-1){ } } }
import com.ximpleware.*; public class getAttrs{ public static void main(String[] s) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("input.xml",false)) // turn off namespace return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/xml/item/@name"); int i=0; while( (i=ap.evalXPath())!=-1){ System.out.println(" item name is ===>"+vn.toString(i+1)); } } }
import com.ximpleware.*; public class simpleQuery { public static void main(String[] s) throws Exception{ String myXML="<resp><status>good</status><msg>hi</msg></resp>"; VTDGen vg = new VTDGen(); vg.setDoc(myXML.getBytes()); vg.parse(false); VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/resp/status"); int i = ap.evalXPath(); if (i!=-1) System.out.println(" result ==>"+vn.toString(i)); } }
import com.ximpleware.*; public class Example1 { public static void main(String[] argv) throws Exception{ VTDGen vg = new VTDGen(); if (vg.parseFile("c:/test2.xml",true)){ VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//TextVar/text()"); int i; while((i=ap.evalXPath())!=-1){ System.out.println(" text value ==>"+vn.toString(i)); } } } }
import com.ximpleware.*; public class simpleXpathSearch{ public static void main(String s[]) throws VTDException,java.io.UnsupportedEncodingException,java.io.IOException{ VTDGen vg = new VTDGen(); vg.setLCLevel(5); if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/*/*[@rsID='1029293']"); int i=0; while((i=ap.evalXPath())!=-1){ // your code logic here }
import com.ximpleware.*; public class queryAttr{ public static void main(String[] s) throws VTDException{ VTDGen vg= new VTDGen(); if (!vg.parseFile("input.xml", false)) return false; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//xml/ep/source/@type"); int i=0; while((i = ap.evalXPath())!=-1){ system.out.println(" attr val ===>"+ vn.toString(i+1)); } } }
VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); int i; ap.selectXPath("/root/device/modelname"); if (vg.parseFile(PATH_TO_FILE,true)){ VTDNav vn = vg.getNav(); ap.bind(vn); // apply XPath to the VTDNav instance // AutoPilot moves the cursor for you while((i=ap.evalXPath())!=-1){ System.out.println("the value is: " + vn.toNormalizedString(vn.getText())); } }
VTDGen vg = new VTDGen(); AutoPilot ap = new AutoPilot(); int i; ap.selectXPath("/root/element"); if (vg.parseFile(FILE_LOCATION,true)){ VTDNav vn = vg.getNav(); ap.bind(vn); // apply XPath to the VTDNav instance // AutoPilot moves the cursor for you while((i=ap.evalXPath())!=-1){ System.out.println("the attribute index val is "+ i +" the attribute string ==>"+vn.toString(vn.getAttrVal("attribute"))); } }
@Override protected void parseElement(ElementParsingResult result) throws ElementParsingException { try { AutoPilot ap = getAutoPilot("/article/front/article-meta/contrib-group/contrib[@contrib-type='author']", vn); while (ap.evalXPath() != -1) { result.addSubResult(nxmlDocumentParser.getParser("contrib").parse()); } releaseAutoPilot(); } catch (NavException | XPathParseException | XPathEvalException e) { throw new ElementParsingException(e); } }
@Override public void parseType(ConcreteType concreteType, VTDNav nav, JCas jcas, byte[] identifier, DocumentTextData docText) throws Exception { VTDNav vn = nav.cloneNav(); for (FeatureTemplate featureTemplate : concreteType.getTypeTemplate().getFeatures()) { for (String xPath : featureTemplate.getXPaths()) { AutoPilot ap = new AutoPilot(vn); ap.selectXPath(xPath); while (ap.evalXPath() != -1) { ConcreteFeature concreteFeature = new ConcreteFeature(featureTemplate); parseSingleType(concreteFeature, vn, jcas, identifier, docText); concreteType.addFeature(concreteFeature); } } } }