|
From: <jz...@xi...> - 2012-10-30 18:47:49
|
That sounds like a good solution to me
----- Original Message -----
From: Mohit Anchlia
To:
Cc:
Sent:Sun, 28 Oct 2012 21:42:24 -0700
Subject:Re: [Vtd-xml-users] Xpath using token
I understand. I've found an alternative solution, as I walk down the
tokens in the order I preserve previous elements and use them as the
xpath when I find the text node.
On Sun, Oct 28, 2012 at 8:33 PM, wrote:
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 [8]("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 [9]("Element name ==> " + vn.toString(i) + " Token
Type "
// + vn.getTokenType(i)); if (type ==
VTDNav.TOKEN_STARTING_TAG) {
log.info [10]("Element name ==> " + vn.toString(i));
sb.append(vn.toString(i) + "/");
if (vn.contains(i, "value")) {
do {
i++;
// log.info [11]("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 [13]("Path: " + sb.toString());
sb.setLength(0);
} } }
}
display(mapList); } private void display(Map mapList) {
for (String key : mapList.keySet()) {
log.info [14]("XPath => " + key + " values =>" +
mapList.get(key));
} }
Links:
------
[1] mailto:jz...@xi...
[2] mailto:moh...@gm...
[3] mailto:jz...@xi...
[4] mailto:vtd...@li...
[5] mailto:jz...@xi...
[6] mailto:moh...@gm...
[7] mailto:vtd...@li...
[8] http://log.info/
[9] http://log.info/
[10] http://log.info/
[11] http://log.info/
[12] http://log.info/
[13] http://log.info/
[14] http://log.info/
|