I need to write a
Java method that removes multiple occurences of a node (and its contents) from within an XML (supplied as a
String).
Here's a sample of the XML
I need to remove all occurences of the element "OLifEExtension" and its contents. I've written a fairly simple method given below, it works but it is very inefficient and takes a lot of time if the XML is large (>=10 MB)
I've also tried regular expressions but can't figure one that works. I've tried the following:
1. <OLifEExtension[^>]+>.+?</OLifEExtension>
2. <OLifEExtension .*?>.*?</OLifEExtension>
3. <OLifEExtension[^>]+/>|<OLifEExtension[^>]+>.+</OLifEExtension>
None of the above regular expressions work. Instead of matching the first "OLifEExtension" element, it matches everything between the first opening "OLifEExtension" and the last ending "OLifEExtension" tag.
Can anyone please tell me a more efficient way of doing this or kindly provide me with a regular expression that will do the job for me?
Many many thanks in advance.
[ December 14, 2008: Message edited by: Tausif Farooqi ]