xml-checker
A Python toolkit for parsing and comparing XML files.
Overview
| Script | Purpose |
|---|---|
xml_parser.py |
Parse XML/text files into ET.Element objects with robust pre-processing |
xml_diff.py |
Compare two parsed XML objects and produce a structured diff report |
Requirements
- Python 3.12+
- Standard library only (no third-party dependencies)
xml_parser.py
Reads an XML or text file and returns a list of top-level ET.Element objects.
Files with multiple root-level elements are supported by wrapping content in a temporary <_root_> element before parsing.
Pre-processing pipeline (applied in order before parsing):
| Step | What is removed |
|---|---|
| 1 | <!-- comments --> |
| 2 | <!DOCTYPE ...> declarations (including internal DTD subsets) |
| 3 | Processing instructions <?...?> (the XML declaration <?xml ...?> is kept until step 4) |
| 4 | XML declaration <?xml ...?> |
| 5 | Custom &entity; references (built-ins &, <, >, ', " are preserved) |
Namespace URIs are stripped from all tag names and attribute keys after parsing.
CLI
python xml_parser.py <file.xml|file.txt> [output.txt]
Output file defaults to output.txt.
Python API
from xml_parser import parse_file, display_elements, save_elements_to_file
elements = parse_file("input.xml") # list[ET.Element]
display_elements(elements) # print to stdout
save_elements_to_file(elements, "out.txt") # write to file
xml_diff.py
Compares two XML objects and generates a detailed diff report covering:
- Summary – total tags, tags exclusive to each object, common tags, and total attribute differences.
- Tag differences – element paths present in one object but not the other.
- Attribute differences – per-element, per-attribute value comparison (grouped by depth level).
CLI
python xml_diff.py <file1.xml|file1.txt> <file2.xml|file2.txt> [output.txt] [--tag-key=<attr>]
| Argument | Required | Description |
|---|---|---|
file1 |
Yes | First XML file |
file2 |
Yes | Second XML file |
output.txt |
No | Report output path (default: output.txt) |
--tag-key=<attr> |
No | Attribute used to disambiguate sibling elements in paths (default: id) |
Python API
from xml_parser import parse_file
from xml_diff import build_report, save_report
obj1 = parse_file("a.xml")
obj2 = parse_file("b.xml")
report = build_report(obj1, obj2, tag_key="id")
print(report)
save_report(report, "output.txt")
Sample Files
The samples/ folder contains example files organised by use case.
Parser samples — samples/parser/
| Input | Expected output | Description |
|---|---|---|
simple.xml |
simple_output.txt |
Basic XML with nested elements and attributes |
complex.xml |
complex_output.txt |
Demonstrates all pre-processing: comments, DOCTYPE, processing instructions, namespaces, and entity references |
python xml_parser.py samples/parser/simple.xml samples/parser/simple_output.txt
python xml_parser.py samples/parser/complex.xml samples/parser/complex_output.txt
Diff samples — samples/diff/
| File pair | Expected report | Scenario |
|---|---|---|
empty_a.xml / empty_b.xml |
empty_report.txt |
Both files contain no XML elements → "Both objects are empty, so there is nothing to compare." |
same_a.xml / same_b.xml |
same_report.txt |
Identical XML structure and attributes → no differences reported |
different_a.xml / different_b.xml |
different_report.txt |
Server configs with differing hosts, ports, drivers, and feature sets → full diff report |
python xml_diff.py samples/diff/empty_a.xml samples/diff/empty_b.xml samples/diff/empty_report.txt
python xml_diff.py samples/diff/same_a.xml samples/diff/same_b.xml samples/diff/same_report.txt
python xml_diff.py samples/diff/different_a.xml samples/diff/different_b.xml samples/diff/different_report.txt
Metadata
Release files for xml-checker 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xml_checker-1.0.0.tar.gz | 9.3 kB | Without provenance | Details for xml_checker-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xml_checker-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for xml_checker-1.0.0-py3-none-any.whl |
Total release size: 18.9 kB
Release files / xml_checker-1.0.0.tar.gz
| Download URL | xml_checker-1.0.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3177e7ad73ca2764c6b0e488e9e9ac6c3bc03fbc9ddf488daec85cc779d67d85
|
|
BLAKE2b-256 checksum How to use checksums |
87d9a1543dd22cd6236258fe2fc43a65eddd3124e9fe8bb2c5e707321172e958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / xml_checker-1.0.0-py3-none-any.whl
| Download URL | xml_checker-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c61e5266afb487aad2117ef2396b41b47200e89ff5e5974386a224ff6b1e89ff
|
|
BLAKE2b-256 checksum How to use checksums |
59c005d0aa1f482600a954bdb59ea01853b7f50492f5b4aa04a2700a7700fd4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for xml-checker 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.