{"id":15445173,"url":"https://github.com/ccubed/dyslexml","last_synced_at":"2025-03-28T08:15:16.299Z","repository":{"id":57424896,"uuid":"92600651","full_name":"ccubed/Dyslexml","owner":"ccubed","description":"Have you ever wanted to make XML documents dictionaries? Say no more fam.","archived":false,"fork":false,"pushed_at":"2017-05-30T09:10:35.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T10:46:16.222Z","etag":null,"topics":["python","python3","xml"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ccubed.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}},"created_at":"2017-05-27T13:34:06.000Z","updated_at":"2019-10-04T16:18:26.000Z","dependencies_parsed_at":"2022-09-10T05:23:09.664Z","dependency_job_id":null,"html_url":"https://github.com/ccubed/Dyslexml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccubed%2FDyslexml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccubed%2FDyslexml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccubed%2FDyslexml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ccubed%2FDyslexml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ccubed","download_url":"https://codeload.github.com/ccubed/Dyslexml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245991585,"owners_count":20706129,"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":["python","python3","xml"],"created_at":"2024-10-01T19:44:11.917Z","updated_at":"2025-03-28T08:15:16.273Z","avatar_url":"https://github.com/ccubed.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dyslexml\n# Thanks to Devon [Ikusaba-san](https://github.com/Ikusaba-san) for the name\nDo you hate XML with a passion? Don't worry, I do too. Sadly, working with XML is a requirement foisted upon many of us.\nThis used to be a painful task, but not anymore. Now you have Dyslexml. Dyslexml is the Utility Knife for general purpose XML parsing.\n\n# Features\n## XML to Dictionary\nWhy work with XML when you can convert absolutely any valid (and hell, even some invalid) XML document into a Dictionary!\nWant an example? Well step right up my friend! I have got you covered.\n### Example\n#### XML Document\nThis will be our document for the run.\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003canimetitles\u003e\n\t\u003canime aid=\"1\"\u003e\n\t\t\u003ctitle xml:lang=\"en\" type=\"short\"\u003eCotS\u003c/title\u003e\n\t\t\u003ctitle xml:lang=\"fr\" type=\"official\"\u003eCrest of the Stars\u003c/title\u003e\n\t\t\u003ctitle xml:lang=\"en\" type=\"official\"\u003eCrest of the Stars\u003c/title\u003e\n\t\t\u003ctitle type=\"official\" xml:lang=\"pl\"\u003eCrest of the Stars\u003c/title\u003e\n\t\t\u003ctitle type=\"syn\" xml:lang=\"cs\"\u003eHvÄzdnĂ˝ erb\u003c/title\u003e\n\t\t\u003ctitle xml:lang=\"x-jat\" type=\"main\"\u003eSeikai no Monshou\u003c/title\u003e\n\t\t\u003ctitle xml:lang=\"x-jat\" type=\"short\"\u003eSnM\u003c/title\u003e\n\t\t\u003ctitle type=\"syn\" xml:lang=\"zh-Hans\"\u003ećçäšçşšçŤ \u003c/title\u003e\n\t\t\u003ctitle xml:lang=\"ja\" type=\"official\"\u003ećçăŽç´çŤ \u003c/title\u003e\n\t\u003c/anime\u003e\n  ...\n\u003c/animetitles\u003e\n```\n#### Dictionary\nAnd behold, our beautiful dictionary. You'll notice some things which I will explain a little below and further in the docs.\nAlso, this dictionary was printed by converting it to json, because pprint is awful and the json printer is much nicer.\n```python\n{\n   \"animetitles\": {\n      \"children\": {\n         \"anime\": [\n            {\n               \"value\": null,\n               \"children\": {\n                  \"title\": {\n                     \"children\": [\n                        {\n                           \"value\": \"CotS\",\n                           \"children\": null,\n                           \"type\": \"child\",\n                           \"attributes\": {\n                              \"lang\": \"en\",\n                              \"type\": \"short\"\n                           }\n                        },\n                        {\n                           \"value\": \"Crest of the Stars\",\n                           \"children\": null,\n                           \"type\": \"child\",\n                           \"attributes\": {\n                              \"lang\": \"fr\",\n                              \"type\": \"official\"\n                           }\n                        }\n```\nTo see the full example, go look check out the [gist](https://gist.github.com/ccubed/781dafce4c4d17474cf31a39eff29b9a).\n### So parsing\nThe dictionaries are consistent once you understand the process. The root of the dictionary is always the root node of the document - animetitles here.\nIt then moves down the line and checks each child element to build a tree from that element. If the element has a text value, it is stored in value.\nAttributes are stored as dictionaries with their key/value pairs appropriately preserved. At the moment I throw away namespaces, but I intend to provide an option to control that behavior.\nThere are 3 types: root is the root node, child is any node which contains data and is under root and a node is a special type that holds multiple children.\nWhen any of type, value, children or attributes is empty it will be replaced with None.\n#### What about node\nIn our example, we have many titles. Each anime has around six or more. I could have made a list of title children, but instead I decided to nest them.\nThis is where the node type comes in. The node type tells you that every child contained in children is of the type that its parent is.\nIn our example above, the **title** attribute is a node. Each child contained in the children of that dictionary is a title.\nI thought this looked better, because you could think of it programmatically as for each title.\n\n# Usage\n## XML to Dictionary\n```python\nimport dyslexml\ndyslexml.Dyslexml.toDict(my_xml_string)\n```\n\n## Python Object to XML\n```python\nimport dyslexml\na = {'a': 1, 'b': 2, 3: 'This is a long key', bytes(10): 'This is a crazy but acceptable key because I'm basically an ascii message'}\ndyslexml.Dyslexml.toXml(a)\n```\n\n## Typing that out is hard\n```python\nfrom dyslexml import Dyslexml\na = Dyslexml()\na.toDict([1,2,3])\na.toXml(my_xml_string)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccubed%2Fdyslexml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fccubed%2Fdyslexml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fccubed%2Fdyslexml/lists"}