NxmlElementParser extends NxmlParser { 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())); } 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(); } } NxmlElementParser(NxmlDocumentParser nxmlDocumentParser); final ElementParsingResult parse();  }
@Test public void testGetElementPath() throws Exception { JCas cas = JCasFactory.createJCas("de.julielab.jcore.types.jcore-document-meta-pubmed-types", "de.julielab.jcore.types.jcore-document-structure-pubmed-types"); NxmlDocumentParser documentParser = new NxmlDocumentParser(); documentParser.reset(new File("src/test/resources/documents-recursive/PMC2847692.nxml.gz"), cas); DefaultElementParser parser = new DefaultElementParser(documentParser); String xpath = "/article"; parser.moveToXPath(xpath); assertEquals(xpath, parser.getElementPath()); xpath = "/article/front/article-meta/contrib-group"; parser.moveToXPath(xpath); assertEquals(xpath, parser.getElementPath()); xpath = "/article/body/sec/title"; parser.moveToXPath(xpath); assertEquals(xpath, parser.getElementPath()); xpath = "/article/front/journal-meta"; parser.moveToXPath(xpath); assertEquals(xpath, parser.getElementPath()); }