← ClaudeAtlas

files-edit-xmllisted

Use when creating, generating, editing, or validating an XML file - app config, pfSense config.xml, pom.xml/build config, SVG, RSS, SOAP, .NET/Java config - especially when modifying an existing document or producing one programmatically. Use instead of hand-typing XML or editing it with sed/regex/string concatenation.
bitranox/bitranox-skills · ★ 1 · Data & Documents · score 57
Install: claude install-skill bitranox/bitranox-skills
# Edit XML with a Python library, never by hand ## Overview Build and edit XML by parsing into an element tree, modifying the tree, then serializing - and re-parse to confirm it is well-formed. Editing XML as raw text (`sed`, regex, f-strings) breaks on namespaces, attribute escaping, CDATA, and entity quoting, and silently produces malformed or wrong-structured documents. A library serialization is well-formed by construction; re-parsing verifies it. ## Library - **`lxml`** (`from lxml import etree`) - fast C parser, full XPath, namespaces, pretty-print, and DTD/XML-Schema/RelaxNG validation. `pip install lxml`. Preferred over stdlib `xml.etree.ElementTree` (weaker XPath, no schema validation) and over `minidom`/`xmltodict`. See **bitranox:coding-python-use-modern-libraries** for the wider list. Reach for the structured editors for the other formats too: **bitranox:files-edit-json**, **bitranox:files-edit-toml**, **bitranox:files-edit-yml**. **Safety:** for XML from an untrusted source, disable entity expansion and network access to avoid XXE / billion-laughs: `etree.XMLParser(resolve_entities=False, no_network=True, dtd_validation=False)`. ## Pattern: parse -> edit the tree -> serialize -> re-parse to validate ```python from lxml import etree parser = etree.XMLParser(remove_blank_text=True, resolve_entities=False) tree = etree.parse("config.xml", parser) # parse into an element tree root = tree.getroot() # edit via XPath: append a host override under <unb