Clear an XML element and its parent to free memory.
(elem)
| 4313 | |
| 4314 | |
| 4315 | def clear_element(elem): |
| 4316 | """Clear an XML element and its parent to free memory.""" |
| 4317 | try: |
| 4318 | elem.clear() |
| 4319 | parent = elem.getparent() |
| 4320 | if parent is not None: |
| 4321 | while elem.getprevious() is not None: |
| 4322 | del parent[0] |
| 4323 | parent.remove(elem) |
| 4324 | except Exception as e: |
| 4325 | logger.warning(f"Error clearing XML element: {e}", exc_info=True) |
| 4326 | |
| 4327 | |
| 4328 | def detect_file_format(file_path=None, content=None): |
no outgoing calls
no test coverage detected