This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Now i want to get elements based on search criteria entered by user ..e.g if user enters a* then i want all the elements whose name value starts with a ... so i should get first and last elements similarly for dept..
before searching i have what attribute ( name or dept) to search and by pattern (attribute value a*b*) to search .
If you load the XML document into a DOM, then you can use XPath to search it. By default Java supports XPath 1.0, which has a "starts-with" string function so you can find elements whose Name attribute value starts with "a", for example. XPath 1.0 doesn't support regular expressions, but XPath 2.0 does. It looks to me like you might be able to use XPath 2.0 on your DOM if you could track down a suitable XPath 2.0 provider (XPathFactory allows you to load non-default providers) but I've never done that and never even seen anything which claims to do it.
You might find it easier just to traverse the elements in your DOM and compare the Name attributes using Java code for the regular expressions. You could use XPath to find all of the Name attributes and then apply the regular expressions to them in Java is what I mean.