@@ -232,6 +232,8 @@ public interface Cursor {
232
232
233
233
void remove () throws Ex ;
234
234
235
+ void removeChildren (Predicate <Cursor > predicate ) throws Ex ;
236
+
235
237
String text ();
236
238
237
239
String describePath ();
@@ -272,7 +274,7 @@ public interface Cursor {
272
274
<R > void update (R payload , Inserter <R > inserter ) throws Ex ;
273
275
274
276
/**
275
- * @param attributeName
277
+ * @param attributeName Name of the attribute
276
278
* @return True if the node has an attribute with the given name
277
279
*/
278
280
boolean hasAttr (String attributeName );
@@ -477,6 +479,9 @@ public <R> void update(R payload, Inserter<R> inserter) {
477
479
public void remove () throws Ex {
478
480
}
479
481
482
+ @ Override
483
+ public void removeChildren (Predicate <Cursor > predicate ) throws Ex { }
484
+
480
485
@ Override
481
486
public boolean hasAttr (String attributeName ) {
482
487
return false ;
@@ -670,6 +675,25 @@ public void remove() throws Ex {
670
675
node .getParentNode ().removeChild (node );
671
676
}
672
677
678
+ @ Override
679
+ public void removeChildren (Predicate <Cursor > predicate ) throws Ex {
680
+ NodeList childNodes = node .getChildNodes ();
681
+ List <Cursor > toBeRemoved = new ArrayList <>();
682
+
683
+ for (int i = 0 ; i < childNodes .getLength (); i ++) {
684
+ Node childNode = childNodes .item (i );
685
+ Cursor cursor = new NodeCursor (document , ancestors , childNode , i );
686
+
687
+ if (predicate .test (cursor )) {
688
+ toBeRemoved .add (cursor );
689
+ }
690
+ }
691
+
692
+ for (Cursor cursor : toBeRemoved ) {
693
+ cursor .remove ();
694
+ }
695
+ }
696
+
673
697
@ Override
674
698
public <R > R extract (Class <R > type ) throws Ex {
675
699
final Extractor <R > extractor = extractorFor (type );
0 commit comments