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))); } }
/** * Throws an exception if the VTDNav cursor is not set to an element * starting tag. * * @throws NavException */ private void checkCursorPosition() throws NavException { if (vn.getTokenType(vn.getCurrentIndex()) != VTDNav.TOKEN_STARTING_TAG) throw new IllegalStateException("VTDNav is positioned incorrectly. It must point to a starting tag."); if (!vn.toString(vn.getCurrentIndex()).equals(elementName)) throw new IllegalStateException( "VTDNav is positioned incorrectly. It is expected to be positioned at the starting tag \"" + elementName + "\" but it is set to \"" + vn.toString(vn.getCurrentIndex()) + "\"."); }
@Override protected void beforeParseElement() throws ElementParsingException { // since this parser does not know the element is is used upon, set // it first for the parsing result creation try { elementName = vn.toString(vn.getCurrentIndex()); } catch (NavException e) { throw new ElementParsingException(e); } }
import com.ximpleware.*; public class getContent { public static void main(String s[]) throws VTDException{ VTDGen vg = new VTDGen(); if (!vg.parseFile("C:\\Users\\HC\\Desktop\\dataset\\book.xml", false)) return; VTDNav vn = vg.getNav(); if (vn.toElement(VTDNav.FIRST_CHILD, "book")){ long l = vn.getContentFragment(); System.out.println( "book content ==> "); System.out.println(vn.toString((int)l, (int)(l<<32))); } } }
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 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 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 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 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)); } }
VTDGen vg= new VTDGen(); if (vg.parseFile("input.xml",false)){ VTDNav vn = vg.getNav(); vn.toElement(VTDNav.FIRST_CHILD); int i = vn.getText(); if (i!=-1) System.out.println(" text node is "+vn.toString(i)); }
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)); } } }
final protected void toString(StringBuilder sb, int index) throws NavException { /*int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) toRawString(sb, index);*/ int len,type; len = getTokenLength2(index); type= getTokenType(index); int offset = getTokenOffset(index); if (type!=VTDNav.TOKEN_CDATA_VAL) toString(offset, len, sb); else toRawString(offset, len, sb); }
final protected void toString(StringBuilder sb, int index) throws NavException { /*int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) toRawString(sb, index);*/ int len,type; len = getTokenLength2(index); type= getTokenType(index); int offset = getTokenOffset(index); if (type!=VTDNav.TOKEN_CDATA_VAL) toString(offset, len, sb); else toRawString(offset, len, sb); }
final protected void toString(StringBuilder sb, int index) throws NavException { /*int type = getTokenType(index); if (type!=TOKEN_CHARACTER_DATA && type!= TOKEN_ATTR_VAL) toRawString(sb, index);*/ int len,type; len = getTokenLength2(index); type= getTokenType(index); int offset = getTokenOffset(index); if (type!=VTDNav.TOKEN_CDATA_VAL) toString(offset, len, sb); else toRawString(offset, len, sb); }
public static String getElementText(VTDNav vn) throws NavException { StringBuilder sb = new StringBuilder(); int depth = vn.getCurrentDepth(); int i = vn.getCurrentIndex(); while (vn.getTokenType(i) == VTDNav.TOKEN_STARTING_TAG) i++; while (vn.getTokenDepth(i) >= depth && !(vn.getTokenType(i) == VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(i) == depth) && i < vn.getTokenCount()) { if (vn.getTokenType(i) == VTDNav.TOKEN_CHARACTER_DATA || vn.getTokenType(i) == VTDNav.TOKEN_CDATA_VAL) sb.append(vn.toString(i)); i++; } return sb.toString(); }
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"))); } }
protected String moveToNextStartingTag() throws DocumentParsingException { try { int i = vn.getCurrentIndex(); int tokenType = vn.getTokenType(i); while (tokenType != VTDNav.TOKEN_STARTING_TAG && i < vn.getTokenCount()) ++i; vn.recoverNode(i); return vn.toString(vn.getCurrentIndex()); } catch (NavException e) { throw new DocumentParsingException(e); } }