| 142 | self.previousSibling.nextSibling = self |
| 143 | |
| 144 | def replaceWith(self, replaceWith): |
| 145 | oldParent = self.parent |
| 146 | myIndex = self.parent.index(self) |
| 147 | if hasattr(replaceWith, "parent")\ |
| 148 | and replaceWith.parent is self.parent: |
| 149 | # We're replacing this element with one of its siblings. |
| 150 | index = replaceWith.parent.index(replaceWith) |
| 151 | if index and index < myIndex: |
| 152 | # Furthermore, it comes before this element. That |
| 153 | # means that when we extract it, the index of this |
| 154 | # element will change. |
| 155 | myIndex = myIndex - 1 |
| 156 | self.extract() |
| 157 | oldParent.insert(myIndex, replaceWith) |
| 158 | |
| 159 | def replaceWithChildren(self): |
| 160 | myParent = self.parent |