From: <jz...@xi...> - 2012-10-29 03:33:58
|
do you know that for any text node there are unlimited ways to address it using XPath//* will definitively do, it therefore can be computationally expensive to accomplish what u look for ----- Original Message ----- From: Mohit Anchlia To: Cc: Sent:Fri, 26 Oct 2012 21:56:15 -0700 Subject:Re: [Vtd-xml-users] Xpath using token For every text node I need to provde a complete xpath, this xpath goes as column in the database. On Fri, Oct 26, 2012 at 7:25 PM, wrote: Getting the xpath representation of a node is neither easy nor unique, why dont u need it in the first place? ----- Original Message ----- From:Mohit Anchlia To: Cc: Sent:Fri, 26 Oct 2012 14:20:13 -0700 Subject:[Vtd-xml-users] Xpath using token From previous suggestion I switched using this logic: The problem is that I am not able to get full xpath down to the leaf. I am only able to get 2 paths. So if I have: value ..... I am only getting c/d/value. Is there a trick I can use here to get the entire path like a/b/c/d/value string ? Only other option I see is to fall back to recursive method. public void navigator(byte[] b) throws NavException, XPathParseException, XPathEvalException, EncodingException, EOFException, EntityException, ParseException { VTDGen vg = new VTDGen(); vg.setDoc(b); vg.parse(true); log.info [4]("File found"); VTDNav vn = vg.getNav(); int idx = -1, type = -1; StringBuilder sb = new StringBuilder(); Map mapList = new HashMap(); for (int i = 0; i < vn.getTokenCount(); i++) { type = vn.getTokenType(i); // log.info [5]("Element name ==> " + vn.toString(i) + " Token Type " // + vn.getTokenType(i)); if (type == VTDNav.TOKEN_STARTING_TAG) { log.info [6]("Element name ==> " + vn.toString(i)); sb.append(vn.toString(i) + "/"); if (vn.contains(i, "value")) { do { i++; // log.info [7]("Text Element name ==> " + vn.toString(i) // + " Token Type " + vn.getTokenType(i)); } while (i < vn.getTokenCount() && (vn.getTokenType(i) != VTDNav.TOKEN_CHARACTER_DATA) & if (i < vn.getTokenCount() & addInMap(sb.toString(), vn.toString(i), mapList); log.info [9]("Path: " + sb.toString()); sb.setLength(0); } } } } display(mapList); } private void display(Map mapList) { for (String key : mapList.keySet()) { log.info [10]("XPath => " + key + " values =>" + mapList.get(key)); } } Links: ------ [1] mailto:jz...@xi... [2] mailto:moh...@gm... [3] mailto:vtd...@li... [4] http://log.info/ [5] http://log.info/ [6] http://log.info/ [7] http://log.info/ [8] http://log.info/ [9] http://log.info/ [10] http://log.info/ |