• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting nodes with regular expression

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I do have xml like this

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 .

it is possible ? if yes please tell me
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic