| 63 | return obj |
| 64 | |
| 65 | def parse_semi_formatted_xml(text): |
| 66 | text = text.strip().replace('\r', '').replace('\t', '').replace('\n', '') |
| 67 | |
| 68 | # text = text.replace('```xml', '').replace('```', '') |
| 69 | |
| 70 | soup = BeautifulSoup(text, 'html.parser') |
| 71 | |
| 72 | obj = {} |
| 73 | |
| 74 | output = soup.find('output') |
| 75 | all_children = output.find_all(recursive=False) |
| 76 | |
| 77 | for child in all_children: |
| 78 | tag_name = child.name |
| 79 | name = child.get('name').lower() |
| 80 | |
| 81 | if tag_name == 'string': |
| 82 | contents = child.text.replace('\r', '').replace('\t', '').split('\n') |
| 83 | contents = [content for content in contents if content != ''] |
| 84 | content = "\n".join(contents) |
| 85 | obj[name] = content |
| 86 | elif tag_name == "list": |
| 87 | obj[name] = [] |
| 88 | for item_tag in child.find_all('item'): |
| 89 | item = {} |
| 90 | for item_child in item_tag.find_all(recursive=False): |
| 91 | item_name = item_child.name.lower() |
| 92 | item_content = item_child.text.replace('\r', '').replace('\t', '').replace('\n', '') |
| 93 | item[item_name] = item_content |
| 94 | obj[name].append(item) |
| 95 | |
| 96 | elif tag_name == "map": |
| 97 | obj[name] = {} |
| 98 | for item_tag in child.find_all('string'): |
| 99 | item_name = item_tag.get('name').lower() |
| 100 | item_content = item_tag.text.replace('\r', '').replace('\t', '').replace('\n', '') |
| 101 | obj[name][item_name] = item_content |
| 102 | return obj, soup |
| 103 | |
| 104 | def convert_to_json_serializable(data): |
| 105 | """ |