public selectElement ( System en ) : void | ||
en | System | java.lang.String /// |
return | void |
static void Main(string[] args) { try { //File f = new File("bioinfo.xml"); // counting child elements of parlist int count = 0; // counting child elements of parlist named "par" int par_count = 0; VTDGen vg = new VTDGen(); if (vg.parseFile("./bioinfo.xml", true)) { VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(); ap.bind(vn); ap.selectXPath("/bix/package/command/parlist"); while (ap.evalXPath() != -1) count++; ap.selectXPath("/bix/package/command/parlist/par"); while (ap.evalXPath() != -1) par_count++; // print out the results Console.WriteLine(" count ====> " + count); Console.WriteLine(" par_count ==> " + par_count); // verify results using iterators int v = 0; vn.toElement(VTDNav.ROOT); ap = new AutoPilot(vn); ap.selectElement("par"); while (ap.iterate()) { if (vn.getCurrentDepth() == 4) { v++; } } Console.WriteLine(" verify ==> " + v); } } catch (NavException e) { Console.WriteLine(" Exception during navigation " + e); } catch (XPathParseException e) { } catch (XPathEvalException e) { } }
static void Main(string[] args) { try { // counting child elements of parlist int count = 0; // counting child elements of parlist named "par" int par_count = 0; VTDGen vg = new VTDGen(); if (vg.parseFile("./bioinfo.xml", true)) { VTDNav vn = vg.getNav(); if (vn.matchElement("bix")) { // match blix // to first child named "package" if (vn.toElement(VTDNav.FC, "package")) { do { Console.WriteLine("package"); // to first child named "command" if (vn.toElement(VTDNav.FC, "command")) { do { Console.WriteLine("command"); if (vn.toElement(VTDNav.FC, "parlist")) { do { Console.WriteLine("parlist"); count++; //increment count if (vn.toElement(VTDNav.FC)) { do { if (vn.matchElement("par")) par_count++; } while (vn.toElement(VTDNav.NS)); vn.toElement(VTDNav.P); } } while (vn.toElement(VTDNav.NS, "parlist")); vn.toElement(VTDNav.P); } } // to next silbing named "command" while (vn.toElement(VTDNav.NS, "command")); vn.toElement(VTDNav.P); // go up one level } else Console.WriteLine(" no child element named 'command' "); // verify result } while (vn.toElement(VTDNav.NS, "package")); // to next sibling named "package" vn.toElement(VTDNav.P); // go up one level } else Console.WriteLine(" no child element named 'package' "); } else Console.WriteLine(" Root is not 'bix' "); // print out the results Console.WriteLine(" count ====> " + count); Console.WriteLine(" par_count ==> " + par_count); // verify results using iterators int v = 0; vn.toElement(VTDNav.ROOT); AutoPilot ap = new AutoPilot(vn); ap.selectElement("par"); while (ap.iterate()) { if (vn.getCurrentDepth() == 4) { v++; } } Console.WriteLine(" verify ==> " + v); } } catch (NavException e) { Console.WriteLine(" Exception during navigation " + e); } }
public int computeContextSize(Predicate p, VTDNav vn){ bool b = false; Predicate tp = null; int i = 0; AutoPilot ap; switch(currentStep.axis_type){ case AxisType.CHILD: if (currentStep.nt.testType != NodeTest.TEXT){ b = vn.toElement(VTDNav.FIRST_CHILD); if (b) { do { if (currentStep.eval(vn, p)) { i++; } } while (vn.toElement(VTDNav.NS)); vn.toElement(VTDNav.PARENT); currentStep.resetP(vn,p); return i; } else return 0; }else { TextIter ti = new TextIter(); ti.touch(vn); while((ti.getNext())!=-1){ if (currentStep.evalPredicates(vn,p)){ i++; } } currentStep.resetP(vn,p); return i; } case AxisType.DESCENDANT_OR_SELF: case AxisType.DESCENDANT: case AxisType.PRECEDING: case AxisType.FOLLOWING: String helper = null; if (currentStep.nt.testType == NodeTest.NODE){ helper = "*"; }else { helper = currentStep.nt.nodeName; } ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF ) if (currentStep.nt.testType == NodeTest.NODE) ap.Special = true; else ap.Special = false; //currentStep.o = ap = new AutoPilot(vn); if (currentStep.axis_type == AxisType.DESCENDANT_OR_SELF) if (currentStep.nt.localName!=null) ap.selectElementNS(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement(helper); else if (currentStep.axis_type == AxisType.DESCENDANT) if (currentStep.nt.localName!=null) ap.selectElementNS_D(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_D(helper); else if (currentStep.axis_type == AxisType.PRECEDING) if (currentStep.nt.localName!=null) ap.selectElementNS_P(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_P(helper); else if (currentStep.nt.localName!=null) ap.selectElementNS_F(currentStep.nt.URL,currentStep.nt.localName); else ap.selectElement_F(helper); vn.push2(); while(ap.iterate()){ if (currentStep.evalPredicates(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); return i; case AxisType.PARENT: vn.push2(); i = 0; if (vn.toElement(VTDNav.PARENT)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); return i; case AxisType.ANCESTOR: vn.push2(); i = 0; while (vn.toElement(VTDNav.PARENT)) { if (currentStep.eval(vn, p)) { i++; } } vn.pop2(); currentStep.resetP(vn,p); return i; case AxisType.ANCESTOR_OR_SELF: vn.push2(); i = 0; do { if (currentStep.eval(vn, p)) { i++; } }while(vn.toElement(VTDNav.PARENT)); vn.pop2(); currentStep.resetP(vn,p); return i; case AxisType.SELF: i = 0; if (vn.toElement(VTDNav.PARENT)){ if (currentStep.eval(vn,p)){ i++; } } currentStep.resetP(vn,p); return i; case AxisType.FOLLOWING_SIBLING: vn.push2(); while(vn.toElement(VTDNav.NEXT_SIBLING)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); return i; case AxisType.PRECEDING_SIBLING: vn.push2(); while(vn.toElement(VTDNav.PREV_SIBLING)){ if (currentStep.eval(vn,p)){ i++; } } vn.pop2(); currentStep.resetP(vn,p); return i; case AxisType.ATTRIBUTE: ap = new AutoPilot(vn); if (currentStep.nt.localName!=null) ap.selectAttrNS(currentStep.nt.URL, currentStep.nt.localName); else ap.selectAttr(currentStep.nt.nodeName); i = 0; while(ap.iterateAttr()!=-1){ if (currentStep.evalPredicates(vn,p)){ i++; } } currentStep.resetP(vn,p); return i; default: throw new XPathEvalException("axis not supported"); } //return 8; }