| 127 | self.previousSibling.nextSibling = self |
| 128 | |
| 129 | def replaceWith(self, replaceWith): |
| 130 | oldParent = self.parent |
| 131 | myIndex = self.parent.index(self) |
| 132 | if hasattr(replaceWith, "parent")\ |
| 133 | and replaceWith.parent is self.parent: |
| 134 | # We're replacing this element with one of its siblings. |
| 135 | index = replaceWith.parent.index(replaceWith) |
| 136 | if index and index < myIndex: |
| 137 | # Furthermore, it comes before this element. That |
| 138 | # means that when we extract it, the index of this |
| 139 | # element will change. |
| 140 | myIndex = myIndex - 1 |
| 141 | self.extract() |
| 142 | oldParent.insert(myIndex, replaceWith) |
| 143 | |
| 144 | def replaceWithChildren(self): |
| 145 | myParent = self.parent |