From: Erik F. <eri...@un...> - 2017-03-30 06:11:32
|
Well, you have to care at least for text tokens and sibling elements. That is, to know if you have left an element you must do something like (vn.getTokenType(index) == VTDNav.TOKEN_STARTING_TAG && vn.getTokenDepth(index) <= elementDepth) || vn.getTokenDepth(index) < elementDepth while this is certainly doable, it took some time to figure it out and is still way more complicated than other APIs. Perhaps it would be helpful to remove the TOKEN_ENDING_TAG constant, because it is confusing, and add a method for element ending detection in the above spirit. > On 29 Mar 2017, at 21:03, Jimmy Zhang <jz...@xi...> wrote: > > it is not kept by the xml parser in order to reduce memory requirement... basically, after start and ending element is done, ending tag serves no significant purpose.. > in fact, the combination of token depth is sufficient to indicate the location in the document... I don't think that part is ambiguous ... > > > > ----- Original Message ----- > From: > Erik Fäßler <eri...@un...> > > To: > "Nil Ratan Sahoo" <nil...@ya...> > Cc: > "vtd...@li..." <vtd...@li...> > Sent: > Tue, 28 Mar 2017 16:13:08 +0200 > Subject: > Re: [Vtd-xml-users] VTD 2.13.1: No TOKEN_ENDING_TAG tokens > > > Hi again, > > I’m afraid the combination of TOKEN_STARTING_TAG and depth is ambiguously. Text tokens and property tokens (e.g. TOKEN_PI_NAME) have the same depth as the element starting tag. > To have explicit TOKEN_ENDING_TAG tokens would be really helpful and enhance the usability of VTD-XML a lot. I am fighting half the day for reliable way to tell whether I’m still in a specific element or not. I will make it eventually, but by now I wished I would just have used StAX. I would have finished hours ago if I had. Actually I’m thinking of changing to StAX right now, might be quicker… > > Best, > > Erik > > On 27 Mar 2017, at 19:39, Nil Ratan Sahoo <nil...@ya... <mailto:nil...@ya...>> wrote: > > Hi Erik, > > By default VTDNav.TOKEN_ENDING_TAG is not part of index, you can use VTDNav.TOKEN_STARTING_TAG and depth to determine end of a tag. > > thanks > Nil > > > On Monday, 27 March 2017 8:01 AM, Erik Fäßler <eri...@un... <mailto:eri...@un...>> wrote: > > > Hi Jimmy, > > I am currently building a program using VTD that parses the XML document element-wise. That means that when a TOKEN_START_TAG token is encountered, a specific class is called that processes the current element. For this, the called class iterates over the tokens until it finds the end of the element. I thought I could just wait for a TOKEN_ENDING_TAG token and check if it matches the original TOKEN_START_TAG and the token depth of the start token. However, it seams that absolutely no token is of type TOKEN_ENDING_TAG in the whole document. My code: > > for (int i = vn.getCurrentIndex(); i < vn.getTokenCount(); i++) { > System.out.println(i); > if (vn.getTokenType(i) == VTDNav.TOKEN_ENDING_TAG) > { > System.out.println("Ending token found!"); > System.out.println(vn.toString(i)); > break; > } > } > > > This code never prints out the “Ending token found!” line. It just counts through all tokens up to vn.getTokenCount(). > > Am I doing something wrong? > > Thanks! > > Best regards, > > Erik > ------------------------------------------------------------------------------ > Check out the vibrant tech community on one of the world's most > engaging tech sites, Slashdot.org <http://slashdot.org/>! http://sdm.link/slashdot <http://sdm.link/slashdot>_______________________________________________ > Vtd-xml-users mailing list > Vtd...@li... <mailto:Vtd...@li...> > https://lists.sourceforge.net/lists/listinfo/vtd-xml-users <https://lists.sourceforge.net/lists/listinfo/vtd-xml-users> > > > |