sunilkumar
sunilkumar

Reputation: 81

Data Retrieving from XML file with some limitation in Java

I am using XML in my project for data to be Insert/Update/Delete.

Currently i am using XPath for doing the above operations from my Java application.

I am facing a problem while retrieving the data from XML. If there are 1000 records in the XML file i want to get the data from XML file with some limit (same as limit in a MySQL select query) in the rows, for implementing the pagination in the view page. I want to display 100 records at a time, so that end-user can click on next button to see all the 1000 records.

Can anyone tell me the best way to full-fill this requirement?


Ya, we can do it with "position()" function but the problem is i want to get the data in an sorted order. position() will return the data from the XML file respective to the given number(in XML file the data may not be in an order). So i want to read the data along with order. I am not able to find the XML query for Sorting and Paginated data in XPath.

Upvotes: 3

Views: 454

Answers (2)

Patrick Bédert
Patrick Bédert

Reputation: 33

As you are using XPath to access your XML data, one possibility could be the position() function to get "paginated" data from the XML. Like:

/path/to/some/element[position() >= 100 and position() <= 200]

Of course you have to store the boundaries (e.g. 100 - 200 as an example) then between user requests.

Ok, if you need sorted output aswell... as far as I know there is no sort function in pure xpath (1.0/2.0). Maybe you are using a library that offers this as an extension. Or you maybe have the possibility to use an XSLT and xsl:sort. Or you use XML binding as written in the other answer.

Upvotes: 0

sudmong
sudmong

Reputation: 2036

You can consider using JAXB instead of direct XML manipulation.

Upvotes: 3

Related Questions