files-edit-xml

Edit and validate XML files programmatically with lxml element trees.

1|Updated Jun 23, 2026
One-click install
npx skills add https://github.com/bitranox/bitranox-skills --skill files-edit-xml-bitranox
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: files-edit-xml
Source: https://github.com/bitranox/bitranox-skills/tree/main/plugins/bitranox/skills/files-edit-xml
Command: npx skills add https://github.com/bitranox/bitranox-skills --skill files-edit-xml-bitranox

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires lxml.

What problem does it solve? Hand-editing XML with sed, regex, or string concatenation breaks on namespaces, attribute escaping, CDATA, and entity quoting, silently producing malformed or wrong-structured documents. This Skill replaces text-level edits with a parse-edit-serialize-reparse workflow that guarantees well-formed output and reviewable diffs. ## Core Features & Use Cases - Tree-based editing: Parse XML into an lxml element tree, modify elements and attributes via XPath and SubElement, then serialize with correct escaping by construction. - Round-trip diff discipline: Prove the serializer reproduces the untouched file byte-for-byte before editing, so a two-value change on a pfSense config.xml produces a reviewable diff instead of thousands of rewritten lines. - Validation and safety: Re-parse serialized output to confirm well-formedness, validate against XSD schemas, and disable entity expansion and network access when parsing untrusted XML to prevent XXE attacks. - Use Case: Add a host override to a firewall's config.xml, verify the round-trip assertion passes, and commit a diff showing exactly the six intended lines. ## Quick Start Use the files-edit-xml skill to add a new host entry to my pfSense config.xml and verify the output re-parses cleanly.

Frequently Asked Questions about files-edit-xml

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I edit an XML file in Python without breaking it?▼

Parse the file with lxml into an element tree, modify elements using find, SubElement, and attribute assignment, then serialize with etree.tostring. Re-parse the output bytes to confirm the document is well-formed before writing it.

lxml vs xml.etree.ElementTree for XML editing?▼

lxml is preferred because it offers full XPath support, namespace handling, pretty-printing, and DTD, XML Schema, and RelaxNG validation. The stdlib ElementTree has weaker XPath and no schema validation, and minidom or xmltodict are not recommended.

Why does editing XML with lxml produce a huge diff?▼

An lxml round-trip rewrites the whole document in its own style, collapsing empty tags, unwrapping CDATA, and changing entity escaping. Prove the serializer reproduces the untouched file byte-for-byte first, then your edit produces a minimal reviewable diff.

How do I safely parse untrusted XML in Python?▼

Create the parser with resolve_entities=False, no_network=True, and dtd_validation=False to block XXE and billion-laughs entity expansion attacks. Never parse untrusted XML with default parser settings.

Why does find return nothing on my XML document?▼

Namespaced documents cause find to fail silently when the namespace prefix is omitted. Pass the namespace map explicitly, for example root.find("ns:tag", nsmap), so the query resolves against the document's declared namespaces.