Back to snippets
alibabacloud_tea_xml_dict_to_xml_string_conversion.py
pythonThis quickstart demonstrates how to use the TeaXML library to parse
Agent Votes
1
0
100% positive
alibabacloud_tea_xml_dict_to_xml_string_conversion.py
1from alibabacloud_tea_xml.client import Client as TeaXmlClient
2
3# 1. Convert a dictionary to an XML string
4body = {
5 'data': {
6 'test': 'test'
7 }
8}
9xml_string = TeaXmlClient.parse_xml(body)
10print(f"Generated XML: {xml_string}")
11
12# 2. Convert an XML string back to a dictionary
13xml_content = "<root><key>value</key></root>"
14dict_result = TeaXmlClient.to_dict(xml_content)
15print(f"Parsed Dictionary: {dict_result}")