Skip to content

Commit ae59c7b

Browse files
committed
Updated file paths
1 parent 293a990 commit ae59c7b

File tree

3 files changed

+404
-0
lines changed

3 files changed

+404
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# XML to Python Converstion\n",
8+
"---"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"### Import modules\n",
16+
"---"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"import xmltodict\n",
26+
"from pprint import pprint"
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"---\n",
34+
"### Set XML string data"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"data = '''\n",
44+
"<?xml version=\"1.0\" ?>\n",
45+
" <root>\n",
46+
" <agenda>\n",
47+
" <items>\n",
48+
" <item>NETCONF History</item>\n",
49+
" <item>NETCONF Overview</item>\n",
50+
" <item>NETCONF Elements</item>\n",
51+
" <item>Lab Overview</item>\n",
52+
" <item>Resources</item>\n",
53+
" </items>\n",
54+
" </agenda>\n",
55+
" </root>\n",
56+
" '''\n",
57+
"xml_data = data.strip()"
58+
]
59+
},
60+
{
61+
"cell_type": "markdown",
62+
"metadata": {},
63+
"source": [
64+
"---\n",
65+
"### Display Raw XML data"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": null,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"print(xml_data)"
75+
]
76+
},
77+
{
78+
"cell_type": "markdown",
79+
"metadata": {},
80+
"source": [
81+
"---\n",
82+
"### Convert XML data to Python objects"
83+
]
84+
},
85+
{
86+
"cell_type": "code",
87+
"execution_count": null,
88+
"metadata": {},
89+
"outputs": [],
90+
"source": [
91+
"py_data = xmltodict.parse(xml_data, dict_constructor=dict)"
92+
]
93+
},
94+
{
95+
"cell_type": "markdown",
96+
"metadata": {},
97+
"source": [
98+
"---\n",
99+
"### Display converted Python data"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"print('** Python Data **')\n",
109+
"pprint(py_data)"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"metadata": {},
115+
"source": [
116+
"---\n",
117+
"### Display the Python object type for the \\<items\\> tag"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": [
126+
"print('** \"items\" XML tag Python Object Type **')\n",
127+
"print(type(py_data['root']['agenda']['items']))"
128+
]
129+
},
130+
{
131+
"cell_type": "markdown",
132+
"metadata": {},
133+
"source": [
134+
"---\n",
135+
"### Display the Python object type for the \\<item\\> tag"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"metadata": {},
142+
"outputs": [],
143+
"source": [
144+
"print('** \"item\" XML tag Python Object Type **')\n",
145+
"print(type(py_data['root']['agenda']['items']['item']))"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"metadata": {},
152+
"outputs": [],
153+
"source": []
154+
}
155+
],
156+
"metadata": {
157+
"kernelspec": {
158+
"display_name": "Python 3",
159+
"language": "python",
160+
"name": "python3"
161+
},
162+
"language_info": {
163+
"codemirror_mode": {
164+
"name": "ipython",
165+
"version": 3
166+
},
167+
"file_extension": ".py",
168+
"mimetype": "text/x-python",
169+
"name": "python",
170+
"nbconvert_exporter": "python",
171+
"pygments_lexer": "ipython3",
172+
"version": "3.8.5"
173+
}
174+
},
175+
"nbformat": 4,
176+
"nbformat_minor": 4
177+
}

0 commit comments

Comments
 (0)