Skip to content

Instantly share code, notes, and snippets.

@dogweather
Created September 6, 2025 00:13
Show Gist options
  • Save dogweather/fa719ed73a1601f4a8eeb809bd6e1ba7 to your computer and use it in GitHub Desktop.
Save dogweather/fa719ed73a1601f4a8eeb809bd6e1ba7 to your computer and use it in GitHub Desktop.
# Convert objects to XML
root = ET.Element("toc")
for title in toc.titles:
title_elem = ET.SubElement(root, "title")
title_elem.set("number", str(title.number))
title_elem.set("id", title.id)
title_elem.set("urn", title.urn)
title_elem.text = title.name
# Pretty print the XML
ET.indent(root)
print(ET.tostring(root, encoding='unicode'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment