Extracts specific XML elements from large source files using Python's xml.etree.ElementTree and optional xmllint formatting. Use to isolate complete elements like <InstrumentVector Id="0"> without loading full XML into context.
How this skill is triggered — by the user, by Claude, or both
Slash command
/xml-element-extractor:xml-element-extractorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill enables precise extraction of XML elements from source files using Python's standard library (xml.etree.ElementTree), with optional xmllint formatting for clean output. Use this skill when you need to isolate a specific XML element from a larger document while maintaining its complete structure.
This skill enables precise extraction of XML elements from source files using Python's standard library (xml.etree.ElementTree), with optional xmllint formatting for clean output. Use this skill when you need to isolate a specific XML element from a larger document while maintaining its complete structure.
DO NOT READ XML FILES DIRECTLY
This prevents context overflow and maintains performance.
Key advantages of the Python implementation:
To extract an XML element:
Gather the following parameters:
<InstrumentVector Id="0">)Run the extraction script with the three parameters:
python3 scripts/extract_xml_element.py <source_file> <dest_file> <element_tag>
Example:
python3 scripts/extract_xml_element.py source.xml dest.xml '<InstrumentVector Id="0">'
Note: The script is implemented in Python but maintains the .py extension for compatibility with existing workflows. The shebang line ensures it executes with Python.
The script will:
The script provides basic error handling for common issues:
If xmllint is available on the system, the script will automatically format the extracted XML with:
If xmllint is not available, the extracted element will be saved in its original formatting.
# Extract InstrumentVector with Id="0"
python3 scripts/extract_xml_element.py live_set.xml instrument_vector.xml '<InstrumentVector Id="0">'
# Extract MidiTrack element
python3 scripts/extract_xml_element.py tracks.xml midi_track.xml '<MidiTrack Id="42">'
# Extract complex elements with quotes and special characters
python3 scripts/extract_xml_element.py live_set.xml device.xml '<MxDeviceAudioEffect Id="5">'
# This will fail - source file doesn't exist
python3 scripts/extract_xml_element.py missing.xml output.xml '<Element>'
# This will fail - no matching element found
python3 scripts/extract_xml_element.py source.xml output.xml '<NonExistentTag>'
# This will fail - malformed XML
python3 scripts/extract_xml_element.py malformed.xml output.xml '<Element>'
extract_xml_element.py: Main Python script that performs XML element extraction using Python's standard library. The script:
python_xml.md: Reference documentation for XML element extraction process, including explanations of the Python parsing logic and troubleshooting guides for common extraction issues.
The script uses Python's standard library with the following key components:
XML Parsing:
xml.etree.ElementTree.parse(): Parses XML files into structured element treestree.iter(tag_name): Iterates through all elements with matching tag namesET.tostring(): Converts elements back to XML stringsTag Matching Algorithm:
Error Detection:
ET.ParseErrorFormatting Options:
XMLLINT_INDENT environment variable for 2-space indentationxml.dom.minidom for cross-platform compatibilityThe Python implementation provides consistent behavior across:
No platform-specific tools are required, making the skill truly portable.
Guides collaborative design exploration before implementation: explores context, asks clarifying questions, proposes approaches, and writes a design doc for user approval.
Creates structured, bite-sized implementation plans from specs or requirements before writing code. Useful for breaking down multi-step tasks into testable steps with file structure and task boundaries.
Resolves in-progress git merge or rebase conflicts by analyzing history, understanding intent, and preserving both changes where possible. Runs automated checks after resolution.
npx claudepluginhub mattypie/alsdiff --plugin xml-element-extractor