{"id":17348447,"url":"https://github.com/daniel-sc/xml_normalize","last_synced_at":"2025-04-14T20:54:40.413Z","repository":{"id":57401887,"uuid":"347009075","full_name":"daniel-sc/xml_normalize","owner":"daniel-sc","description":"Normalizes xml files. Options include sorting siblings based on provided attribute, remove nodes, normalize whitespace/trim and pretty print.","archived":false,"fork":false,"pushed_at":"2022-11-10T10:33:24.000Z","size":1246,"stargazers_count":4,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T19:44:44.310Z","etag":null,"topics":["normalization","sorting","xml"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daniel-sc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-03-12T09:22:25.000Z","updated_at":"2023-01-21T05:52:35.000Z","dependencies_parsed_at":"2023-01-21T21:02:40.232Z","dependency_job_id":null,"html_url":"https://github.com/daniel-sc/xml_normalize","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fxml_normalize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fxml_normalize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fxml_normalize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fxml_normalize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-sc","download_url":"https://codeload.github.com/daniel-sc/xml_normalize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650426,"owners_count":21139671,"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":["normalization","sorting","xml"],"created_at":"2024-10-15T16:52:26.993Z","updated_at":"2025-04-14T20:54:40.389Z","avatar_url":"https://github.com/daniel-sc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/xml_normalize)](https://www.npmjs.com/package/xml_normalize)\n[![Coverage Status](https://coveralls.io/repos/github/daniel-sc/xml_normalize/badge.svg?branch=main)](https://coveralls.io/github/daniel-sc/xml_normalize?branch=main)\n[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/daniel-sc/xml_normalize.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/daniel-sc/xml_normalize/context:javascript)\n\n# XML Normalize\n\nThis program allows normalizing arbitrary xml files.\nNormalization can be configured:\n\n* sort sibling elements based on some attribute value\n* remove unwanted nodes\n* trim texts\n* normalize whitespaces/line breaks\n\nThis can be used as a post-/pre-processing step to keep diffs small for generated xml files.\n\n## Usage\n\nEither install via `npm i -g xml_normalize` or run directly with `npx xml_normalize`.\n\n```text\nUsage: npx xml_normalize [options]\n\nOptions:\n  -i, --input-file \u003cinputFile\u003e       input file\n  -o, --output-file \u003coutputFile\u003e     output file - if not provided result is printed to stdout\n  -r, --remove-path \u003cremovePath...\u003e  simple XPath(s) to remove elements - e.g. \"/html/head[1]/script\"\n  -s, --sort-path \u003csortPath\u003e         simple XPath that references an attribute to sort - e.g. \"/html/head[1]/script/@src\"\n  --no-pretty                        Disable pretty format output\n  --no-trim                          Disable trimming of whitespace at the beginning and end of text nodes (trims only pure text nodes)\n  --no-attribute-trim                Disable trimming whitespace at the beginning and end of attribute values\n  -tf, --trim-force                  Trim the whitespace at the beginning and end of text nodes (trims as well text adjacent to nested nodes)\n  -n, --normalize-whitespace         Normalize whitespaces inside text nodes and attribute values\n  -d, --debug                        enable debug output\n  -h, --help                         display help for command\n```\n\n## Options and Examples\n\n### Sorting\n\nAllows to sort siblings at a specific path \nwith the same tag name lexicographically\nbased on a specific attribute value.\n\nExample:\n\n```xml\n\u003croot\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"z\"\u003eshould be last\u003c/child\u003e\n    \u003cchild id=\"a\"\u003eshould be first\u003c/child\u003e\n  \u003c/node\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"y\"\u003eshould be last\u003c/child\u003e\n    \u003cchild id=\"b\"\u003eshould be first\u003c/child\u003e\n  \u003c/node\u003e\n\u003c/root\u003e\n```\n\n`npx xml_normalize -s /root/node/child/@id` will create:\n\n```xml\n\u003croot\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"a\"\u003eshould be first\u003c/child\u003e\n    \u003cchild id=\"z\"\u003eshould be last\u003c/child\u003e\n  \u003c/node\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"b\"\u003eshould be first\u003c/child\u003e\n    \u003cchild id=\"y\"\u003eshould be last\u003c/child\u003e\n  \u003c/node\u003e\n\u003c/root\u003e\n```\n\n### Removing\n\nAllows to remove nodes in a specific path.\n\n\nExample:\n\n```xml\n\u003croot\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"z\"\u003eshould be removed\u003c/child\u003e\n    \u003cchild id=\"a\"\u003eshould be removed\u003c/child\u003e\n  \u003c/node\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"y\"\u003eshould stay\u003c/child\u003e\n    \u003cchild id=\"b\"\u003eshould stay\u003c/child\u003e\n  \u003c/node\u003e\n\u003c/root\u003e\n```\n\n`npx xml_normalize -r /root/node[1]/child` will create:\n\n```xml\n\u003croot\u003e\n  \u003cnode/\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"b\"\u003eshould stay\u003c/child\u003e\n    \u003cchild id=\"y\"\u003eshould stay\u003c/child\u003e\n  \u003c/node\u003e\n\u003c/root\u003e\n```\n\n`npx xml_normalize -r /root/node/child` instead, will create:\n\n```xml\n\u003croot\u003e\n  \u003cnode/\u003e\n  \u003cnode/\u003e\n\u003c/root\u003e\n```\n\n### Normalize whitespace\n\nThis option replaces any number of consecutive whitespace, tab, new line characters with a single whitespace (in text nodes).\n\nExample:\n\n```xml\n\u003croot\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"z\"\u003esome    xml\n    has messed up \n    formatting\n    \u003c/child\u003e\n      \n      \n    \u003cchild id=\"sometimes      even attributes are messed \n    up\"\u003esome more     mess\u003c/child\u003e\n  \u003c/node\u003e\n\u003c/root\u003e\n```\n\n`npx xml_normalize --normalize-whitespace` will create:\n\n```xml\n\u003croot\u003e\n  \u003cnode\u003e\n    \u003cchild id=\"z\"\u003esome xml has messed up formatting\u003c/child\u003e\n    \u003cchild id=\"sometimes even attributes are messed up\"\u003esome more mess\u003c/child\u003e\n  \u003c/node\u003e\n\u003c/root\u003e\n```\n\n\n### Paths for sorting and removing\n\nPaths are a simple subset of XPaths.\n\n```\n/ROOT/NODE_NAME[INDEX]/ANOTHER_NODE\n```\n\nSupported:\n\n* Only absolute paths\n* Index access (note in XPath indices are 1-based!)\n* Simple predicates using the following functions (parameters can be string (double quotes) or XPaths):\n  * `starts-with(str,prefix)`\n  * `contains(str,contained)`\n* Node wildcard - e.g `/root/*` to select all nodes in `root` of any type.  \n* Attribute reference in last node - e.g. `/root/node/@id`.\n\n\n## What is this good for?\n\nThis helps to bring xml in a standardized form,\nso that changes can easily be spotted in diff tool or git pull request.\n\nFor example, you could run it as a post processing/pre commit script when re-generating XLIFF translation files \n(or getting them back from your beloved translator in a messed up form).\n\n## Contribute\n\nPRs always welcome :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-sc%2Fxml_normalize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-sc%2Fxml_normalize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-sc%2Fxml_normalize/lists"}