|what are some clean, easy ways to filter XML-based input to a TableViewer object? [message #1071636]
||Sat, 20 July 2013 18:38
| John Smith
Registered: July 2013
The code opens an XML document, builds a JAXB object that represents the contents of that document, selects the relevant data (a List field of other JAXB objects), and feeds that List to a Tableviewer.|
That works great when the data that goes into the Tableviewer doesn't have to be filtered. But when it needs to be filtered, especially when it needs to be filtered based on several criteria, there doesn't seem to be a straightforward way to do it, and for the sake of not scratching off the JAXB idea altogether and starting over with a different approach, ended up:
building an XPath expression based on the chosen filters
marshalling the JAXB Object whose List field was initially fed to the Tableviewer, as an org.w3c.dom.Document object
running the XPath expression against that object
unmarshalling each Node of the returned NodeList as a JAXB object
building a new List whose elements are those JAXB objects
passing the new List as new input to the Tableviewer.
With all the marshalling/unmarshalling it's obviously not an efficient solution, but it works relatively well as long as the number of element does not exceed ~ 5000.
Had I been using .NET, I would have,
built a DataTable object based on the XML document
filtered the data by running an SQL-like query against the DataTable's default DataView
bound the resulting DataTable to the DataGridView control that displays the data
with that in mind, I would like to know if there is a more elegant and efficient way to accomplish what I am trying to accomplish without having to marshal/unmarshal the JAXB object each time the data needs to be filtered based on a combination of arbitrary criteria. If there is a clean way to do all this filtering in a manner similar to the way I would have done it if I had been using .NET, even if it's in a way that doesn't require the use of JAXB at all, I might still have time to make changes to the code.
Powered by FUDForum
. Page generated in 0.07700 seconds