| 220 | super().__init__(file_path, file_mode, encoding) |
| 221 | |
| 222 | def export(self, data, **kwargs): |
| 223 | # Creates the XML file structure. |
| 224 | library = ElementTree.Element("library") |
| 225 | tracks = ElementTree.SubElement(library, "tracks") |
| 226 | if data and isinstance(data[0], dict): |
| 227 | for index, item in enumerate(data): |
| 228 | track = ElementTree.SubElement(tracks, "track") |
| 229 | for key, value in item.items(): |
| 230 | track_details = ElementTree.SubElement(track, key) |
| 231 | track_details.text = value |
| 232 | # Depending on the version of python the encoding needs to change |
| 233 | try: |
| 234 | data = ElementTree.tostring(library, encoding="unicode", **kwargs) |
| 235 | except LookupError: |
| 236 | data = ElementTree.tostring(library, encoding="utf-8", **kwargs) |
| 237 | |
| 238 | self.out_stream.write(data) |