1

I am currently looking to integrate VTD-XML in to our project (as a replacement of a Stax based system).

Our xml files are mostly structured like this:

<header>
  <entry1 timestamp="0"/>
  <entry2 timestamp="1"/>
  <entry1 timestamp="2"/>
  <entry2 timestamp="3"/>
</header>

Is there a way to get VTD-XML to recognize that the timestamps are strictly ordered and to abort a xpath query like /header/*[@timestamp < 2] early?

vtd-xml-author
  • 3,319
  • 4
  • 22
  • 30
fho
  • 6,787
  • 26
  • 71

1 Answers1

1

not that i'm aware of. But you could select the last node:

/header/*[@timestamp = 2]

and then use selectPrecedingNode()

VirgileD
  • 737
  • 1
  • 7
  • 23
  • Hmm ... no that's not what I meant. I want to iterate every entry from x to y (`/header/*[@ts > x and @ts < y]`). But as the program has no idea that the timestamps are ordered it has to check every following timestamp too. – fho Mar 12 '14 at 14:22
  • So perhaps I didn't understand your problem: VTD-XML, with the autopilot evalXPath just puts a cursor on the corresponding nodes. Then you just have to iterate on the nodes with the PrecedingNode and break out of the iteration when it reaches the timestamp you want? – VirgileD Mar 12 '14 at 15:10
  • Sure I could do that, but actually `evalXPath` will return -1 when there are no more entries. I was hoping that there'd be a way to short circuit that with prior knowledge :) – fho Mar 12 '14 at 15:23
  • if you : first evalXPath on a timestamp max value, and then iterate with selectPrecedingNode, the only way evalXPath will return -1 is if you have absolutly no entries with a correct timestamp. It does not look like a big penalty. Whatever... If you find some xpath miracle, let us know. – VirgileD Mar 12 '14 at 15:38
  • I'll just accept the answer. Maybe don't using xpath and checking the attributes myself is an ok alternative. – fho Mar 13 '14 at 12:39
  • This is a clever solution. – vtd-xml-author May 03 '16 at 04:15