File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -550,7 +550,7 @@ def drop(self):
550550 Drop matched nodes from the parent element.
551551 """
552552 try :
553- self .root .getparent ()
553+ parent = self .root .getparent ()
554554 except AttributeError :
555555 # 'str' object has no attribute 'getparent'
556556 raise CannotRemoveElementWithoutRoot (
@@ -561,7 +561,10 @@ def drop(self):
561561 )
562562
563563 try :
564- self .root .drop_tree ()
564+ if self .type == "xml" :
565+ parent .remove (self .root )
566+ else :
567+ self .root .drop_tree ()
565568 except (AttributeError , AssertionError ):
566569 # 'NoneType' object has no attribute 'drop'
567570 raise CannotDropElementWithoutParent (
Original file line number Diff line number Diff line change @@ -1326,3 +1326,10 @@ def test_dont_remove_text_after_deleted_element(self) -> None:
13261326 self .assertEqual (
13271327 sel .get (), "<html><body>Text before. Text after.</body></html>"
13281328 )
1329+
1330+ def test_drop_with_xml_type (self ) -> None :
1331+ sel = self .sscls (text = "<a><b></b><c/></a>" , type = "xml" )
1332+ el = sel .xpath ("//b" )[0 ]
1333+ assert el .root .getparent () is not None
1334+ el .drop ()
1335+ assert sel .get () == "<a><c/></a>"
You can’t perform that action at this time.
0 commit comments