{"id":15432955,"url":"https://github.com/simonw/xml-analyser","last_synced_at":"2025-04-19T17:51:55.967Z","repository":{"id":736536,"uuid":"386686","full_name":"simonw/xml-analyser","owner":"simonw","description":"Simple command line tool for quickly analysing the structure of an arbitrary XML file","archived":false,"fork":false,"pushed_at":"2023-06-02T23:19:18.000Z","size":19,"stargazers_count":29,"open_issues_count":3,"forks_count":3,"subscribers_count":5,"default_branch":"main","last_synced_at":"2024-10-18T07:53:35.308Z","etag":null,"topics":["xml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simonw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2009-11-26T17:11:08.000Z","updated_at":"2024-04-28T11:14:39.000Z","dependencies_parsed_at":"2023-07-05T15:17:05.189Z","dependency_job_id":null,"html_url":"https://github.com/simonw/xml-analyser","commit_stats":{"total_commits":14,"total_committers":2,"mean_commits":7.0,"dds":0.1428571428571429,"last_synced_commit":"a835dbad507b9eaaab8751d6948ab063f12843fe"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fxml-analyser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fxml-analyser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fxml-analyser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simonw%2Fxml-analyser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simonw","download_url":"https://codeload.github.com/simonw/xml-analyser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249753088,"owners_count":21320664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["xml"],"created_at":"2024-10-01T18:29:44.128Z","updated_at":"2025-04-19T17:51:55.950Z","avatar_url":"https://github.com/simonw.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xml-analyser\n\n[![PyPI](https://img.shields.io/pypi/v/xml-analyser.svg)](https://pypi.org/project/xml-analyser/)\n[![Changelog](https://img.shields.io/github/v/release/simonw/xml-analyser?include_prereleases\u0026label=changelog)](https://github.com/simonw/xml-analyser/releases)\n[![Tests](https://github.com/simonw/xml-analyser/workflows/Test/badge.svg)](https://github.com/simonw/xml-analyser/actions?query=workflow%3ATest)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/simonw/xml-analyser/blob/main/LICENSE)\n\nA tool showing various statistics about element usage in an arbitrary XML file.\n\n## Installation\n\n    pip install xml-analyser\n\nOr using [pipx](https://pypa.github.io/pipx/):\n\n    pipx install xml-analyser\n\n## Usage\n\n    xml-analyser example.xml\n\nIf `example.xml` looks like this:\n\n```xml\n\u003cexample\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n  \u003c/foo\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\" c=\"3\"\u003e\n      \u003cbaz\u003eMore text here\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbaz d=\"1\" /\u003e\n  \u003c/foo\u003e\n\u003c/example\u003e\n```\n\n`xml-analyzer example.xml` outputs this:\n\n```json\n{\n    \"example\": {\n        \"count\": 1,\n        \"parent_counts\": {},\n        \"attr_counts\": {},\n        \"child_counts\": {\n            \"foo\": 2\n        }\n    },\n    \"foo\": {\n        \"count\": 2,\n        \"parent_counts\": {\n            \"example\": 2\n        },\n        \"attr_counts\": {},\n        \"child_counts\": {\n            \"bar\": 2,\n            \"baz\": 1\n        }\n    },\n    \"bar\": {\n        \"count\": 2,\n        \"parent_counts\": {\n            \"foo\": 2\n        },\n        \"attr_counts\": {\n            \"a\": 2,\n            \"b\": 2,\n            \"c\": 1\n        },\n        \"child_counts\": {\n            \"baz\": 2\n        }\n    },\n    \"baz\": {\n        \"count\": 3,\n        \"parent_counts\": {\n            \"bar\": 2,\n            \"foo\": 1\n        },\n        \"attr_counts\": {\n            \"d\": 1\n        },\n        \"child_counts\": {},\n        \"count_with_text\": 2,\n        \"max_text_length\": 14\n    }\n}\n```\n\n## Truncating the XML instead\n\nThe `--truncate` option works differently: the XML file passed to this tool will be truncated, by finding any elements with more than two child elements of the same type and truncating to just those two elements.\n\nThis can reduce a large XML file to something that's easier to understand.\n\nGiven an example document like this one:\n\n```xml\n\u003cexample\u003e\n  \u003catop title=\"Example 1\" /\u003e\n  \u003catop title=\"Example 2\" /\u003e\n  \u003catop title=\"Example 3\" /\u003e\n  \u003catop title=\"Example 4\" /\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbar a=\"2\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbar a=\"3\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbar a=\"4\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n  \u003c/foo\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\" c=\"3\"\u003e\n      \u003cbaz\u003eMore text here\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbaz d=\"1\" /\u003e\n  \u003c/foo\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\" c=\"3\"\u003e\n      \u003cbaz\u003eMore text here\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbaz d=\"1\" /\u003e\n  \u003c/foo\u003e\n\u003c/example\u003e\n```\nThe following command:\n\n    xml-analyser example.xml --truncate\n\nWill return the following:\n\n```xml\n\u003cexample\u003e\n  \u003catop title=\"Example 1\" /\u003e\n  \u003catop title=\"Example 2\" /\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbar a=\"2\" b=\"2\"\u003e\n      \u003cbaz\u003eThis has text\u003c/baz\u003e\n    \u003c/bar\u003e\n  \u003c/foo\u003e\n  \u003cfoo\u003e\n    \u003cbar a=\"1\" b=\"2\" c=\"3\"\u003e\n      \u003cbaz\u003eMore text here\u003c/baz\u003e\n    \u003c/bar\u003e\n    \u003cbaz d=\"1\" /\u003e\n  \u003c/foo\u003e\n\u003c/example\u003e\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fxml-analyser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimonw%2Fxml-analyser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimonw%2Fxml-analyser/lists"}