protected void navpush() { nav.push(); fragPosStack.add(fragPos); fragPos = FragmentPosition.BEFORE_OPEN_TAG; }
/** * Returns the value of <tt>xpath</tt> as retrieved when calling * {@link AutoPilot#evalXPathToString()}. * * @param xpath * The XPath for which a value should be returned. * @return The XPath value. * @throws XPathParseException * @throws XPathEvalException * @throws NavException */ protected Optional<String> getXPathValue(String xpath) throws XPathParseException, XPathEvalException, NavException { try { vn.push(); AutoPilot ap = getAutoPilot(xpath, vn); String xpathValue = ap.evalXPathToString().trim(); if (xpathValue != null && xpathValue.length() > 0) return Optional.of(xpathValue); return Optional.empty(); } finally { releaseAutoPilot(); vn.pop(); } }
protected Optional<List<String>> getXPathValues(String xpath) throws XPathParseException, XPathEvalException, NavException { try { vn.push(); List<String> values = new ArrayList<>(); AutoPilot ap = getAutoPilot(xpath, vn); while (ap.evalXPath() != -1) { int text = vn.getText(); if (text != -1) values.add(vn.toString(text)); } if (!values.isEmpty()) return Optional.of(values); return Optional.empty(); } finally { releaseAutoPilot(); vn.pop(); } }
/** * This method returns an absolute XPath-like representation of the position * of the current element. Only simple paths like * /article/front/article-meta will be returned and it is required that the * VTDNav is located at an element starting tag when calling this method. * * @return The path of the current element. * @throws NavException */ protected String getElementPath() throws NavException { try { assert vn.getTokenType(vn .getCurrentIndex()) == VTDNav.TOKEN_STARTING_TAG : "This method only works if the VTDNav is positioned at the beginning of an element."; List<String> pathItems = new ArrayList<>(vn.getCurrentDepth() + 1); vn.push(); do { pathItems.add(vn.toString(vn.getCurrentIndex())); // in the test we append the restriction to starting tags // because in the current version of VTD, the parent of the root // element seems to the doctype, if present. To make this // algorithm more robust and not to rely and seemingly random // behavior of VTD, we stick to actual elements } while (vn.toElement(VTDNav.PARENT) && vn.getTokenType(vn.getCurrentIndex()) == VTDNav.TOKEN_STARTING_TAG); int pathLength = pathItems.size() - 1; return "/" + IntStream.rangeClosed(0, pathLength).mapToObj(i -> pathItems.get(pathLength - i)) .collect(Collectors.joining("/")); } finally { vn.pop(); } }
/** * Moves the VTDNav to the given XPath, which has to point to an element * (and not, for example, an attribute) and calls the registered parser for * the target element. * * @param xpath * The XPath to move to. * @return The element parsing result of the element found at * <tt>xpath</tt>. * @throws XPathParseException * @throws XPathEvalException * @throws NavException * @throws ElementParsingException */ protected Optional<ParsingResult> parseXPath(String xpath) throws XPathParseException, XPathEvalException, NavException, ElementParsingException { try { vn.push(); if (moveToXPath(xpath)) { return Optional.of(nxmlDocumentParser.getParser(vn.toString(vn.getCurrentIndex())).parse()); } log.trace("XPath not found: {}", xpath); return Optional.empty(); } finally { vn.pop(); } }
LOG.debug("getTimeStamp: retrieving custom timestamp to be used when updating RRDs using XPATH {} and pattern {}", group.getTimestampXpath(), pattern); document.push(); AutoPilot ap = new AutoPilot(); ap.bind(document);
while ((i = autoPilot.evalXPath()) != -1) navigator.push(); nodeInterfaces.add(navigator.toString(i + 1));
import com.ximpleware.*; public class queryAttr { public static void main(String[] s) throws VTDException{ VTDGen vg = new VTDGen(); vg.selectLcDepth(5);// improve XPath performance for deep document if (!vg.parseFile("input.xml", false)) return; VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("/BatchItemFullInfoAnswer/Result/Item/ConfiguredItems/OtapiConfiguredItem/Configurators/ValuedConfigurator/@pid"); AutoPilot ap2 = new AutoPilot(vn); ap2.selectXPath("../@vid"); int i=0,j=0; while((i=ap.evalXPath())!=-1){ System.out.println(" attr value for pid is ==>"+vn.toString(i+1)); // notice this is i+1, not i cuz i is the vtd record index for pid vn.push();// maintain consistency of autoPilot with push/pop combo if ((j=ap2.evalXPath())!=-1) System.out.println(" attr value for vid is ==>"+vn.toString(j+1)); // notice this is j+1, not j cuz j is the vtd record index for vid vn.pop(); } } }
LOG.debug("fillCollectionSet: processing resource {}", collectionResource); for (XmlObject object : group.getXmlObjects()) { document.push(); AutoPilot ap = new AutoPilot(); ap.bind(document);
vn.push(); while((j=ap4.evalXPath())!=-1){ elementName = vn.toRawString(j);