{"action":"created","issue":{"url":"https://api.github.com/repos/martinblech/xmltodict/issues/111","repository_url":"https://api.github.com/repos/martinblech/xmltodict","labels_url":"https://api.github.com/repos/martinblech/xmltodict/issues/111/labels{/name}","comments_url":"https://api.github.com/repos/martinblech/xmltodict/issues/111/comments","events_url":"https://api.github.com/repos/martinblech/xmltodict/issues/111/events","html_url":"https://github.com/martinblech/xmltodict/issues/111","id":99433900,"number":111,"title":"Optional attributes and unknown children count","user":{"login":"vovanz","id":1778004,"avatar_url":"https://avatars.githubusercontent.com/u/1778004?v=3","gravatar_id":"","url":"https://api.github.com/users/vovanz","html_url":"https://github.com/vovanz","followers_url":"https://api.github.com/users/vovanz/followers","following_url":"https://api.github.com/users/vovanz/following{/other_user}","gists_url":"https://api.github.com/users/vovanz/gists{/gist_id}","starred_url":"https://api.github.com/users/vovanz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vovanz/subscriptions","organizations_url":"https://api.github.com/users/vovanz/orgs","repos_url":"https://api.github.com/users/vovanz/repos","events_url":"https://api.github.com/users/vovanz/events{/privacy}","received_events_url":"https://api.github.com/users/vovanz/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-08-06T13:28:47Z","updated_at":"2016-02-21T10:40:51Z","closed_at":null,"body":"# What's wrong?\r\n## 1. Optional attributes\r\nIf i have a tag which can look like this:\r\n```xml\r\n<sometag>blablabla</sometag>\r\n```\r\nor like this:\r\n```xml\r\n<sometag attr=\"123\">blablabla</sometag>\r\n```\r\nIn the first case parse result will look like this:\r\n```python\r\n{\r\n    'sometag': 'blablabla'\r\n}\r\n```\r\nand in the second case it will look like:\r\n```python\r\n{\r\n    'sometag': {\r\n        '@attr': '123',\r\n         '#text': 'blablabla'\r\n    }\r\n}\r\n```\r\nSo if I want to get its text content I can't just do something like:\r\n```python\r\nsomething = parse_result['sometag']['#text']\r\n```\r\nI have to write such ugly things:\r\n```python\r\nsomething = parse_result['sometag']\r\nsomething = something['#text'] if type(something) is OrderedDict else something\r\n```\r\n\r\n\r\n\r\n\r\n## 2. Unknown children count\r\nIf I have a tag which can look like this:\r\n```xml\r\n<parent>\r\n    <child>some text</child>\r\n    <child>other text</child>\r\n<parent>\r\n```\r\nAnd I don't know exact children count **(child could be only one!)**\r\nSo I couldn't iterate over children like this:\r\n```python\r\nfor child in parse_result['parent']['child']:\r\n    # some code\r\n```\r\nbecause list would be used only if there are more than one child.\r\nSo in this case I also have to perform some ugly type checking.\r\nLike this:\r\n```python\r\nchildren = parse_result['parent']['child']\r\nchildren = children if type(children) is list else [children]\r\nfor child in children:\r\n    # some code\r\n```\r\n# Suggestion\r\nI suggest to add special mode (triggered by special optional argument passed to *parse* function).\r\nIn this mode it will always use dictionary for describing tags and always use lists for describing children tags."},"comment":{"url":"https://api.github.com/repos/martinblech/xmltodict/issues/comments/186794770","html_url":"https://github.com/martinblech/xmltodict/issues/111#issuecomment-186794770","issue_url":"https://api.github.com/repos/martinblech/xmltodict/issues/111","id":186794770,"user":{"login":"SeanHayes","id":134373,"avatar_url":"https://avatars.githubusercontent.com/u/134373?v=3","gravatar_id":"","url":"https://api.github.com/users/SeanHayes","html_url":"https://github.com/SeanHayes","followers_url":"https://api.github.com/users/SeanHayes/followers","following_url":"https://api.github.com/users/SeanHayes/following{/other_user}","gists_url":"https://api.github.com/users/SeanHayes/gists{/gist_id}","starred_url":"https://api.github.com/users/SeanHayes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SeanHayes/subscriptions","organizations_url":"https://api.github.com/users/SeanHayes/orgs","repos_url":"https://api.github.com/users/SeanHayes/repos","events_url":"https://api.github.com/users/SeanHayes/events{/privacy}","received_events_url":"https://api.github.com/users/SeanHayes/received_events","type":"User","site_admin":false},"created_at":"2016-02-21T10:40:51Z","updated_at":"2016-02-21T10:40:51Z","body":"I'd be happy with the `children = parse_result['parent'][0]['sub'][0]['child']` behavior in all cases, it minimizes the number of code paths I need in my own applications. Otherwise I need an if condition for every node level.\r\n\r\nOtherwise I'm loving this library, thanks!"}}