Complex search query through XML records

tarik01

New Member
I have a list of objects which contain one XML String field. I have to execute an SQL like query for that field, and get a sub list that satisfies the values. I am trying to use XPath. Firstly, I can't figure out the XPath string to achieve this. Secondly, there might be a better way of doing this. I tried searching through SO but the answers don't really address this problemDetailsI have a list of books:\[code\]List <Books> allBooks;\[/code\]The Book class can have an id and details fields. The details is XML.\[code\]class Book{ String id; String details; //XML}\[/code\]Here is a sample of the details xml String:\[code\]<book> <name>Harry Potter and the sorcerer's stone</name> <author>J K Rowling</author> <genre>fantasy</genre> <keyword>wizard</keyword> <keyword>british</keyword> <keyword>hogwarts</keyword> <price>25</price></book>\[/code\]So, uptil here it is all set in stone. It is part of existing code and I cannot change that design.My work is to take the list allBooks & run a query through it, the logic of which is:\[code\] WHERE author = "J K Rowling" AND genre = "fantasy" AND (keyword = "wizard" OR keyword="hogwarts")\[/code\]I considered throwing this data in a DB to run an actual query, but since the list will only contain a couple of hundred records, the overhead of connection, loading data etc is not worth it.Anyone know how to do this through XPath? Any better way of doing this?
 
Back
Top