Diferències
Ací es mostren les diferències entre la revisió seleccionada i la versió actual de la pàgina.
| info:cursos:pue:python-pcpp1:m5:2.1 [04/03/2024 11:34] – creat mate | info:cursos:pue:python-pcpp1:m5:2.1 [04/03/2024 11:37] (actual) – mate | ||
|---|---|---|---|
| Línia 282: | Línia 282: | ||
| In the example above, we use the '' | In the example above, we use the '' | ||
| + | |||
| + | == Building an XML document (part 2) | ||
| + | In addition to the '' | ||
| + | |||
| + | The first one defines the parent element, the second one defines the tag name, and the third (optional) defines the attributes of the element. Let's see how it looks in action and analyze the code in the editor. | ||
| + | |||
| + | <code python> | ||
| + | |||
| + | root = ET.Element(' | ||
| + | movie_1 = ET.SubElement(root, | ||
| + | movie_2 = ET.SubElement(root, | ||
| + | ET.dump(root) | ||
| + | </ | ||
| + | |||
| + | Result: | ||
| + | < | ||
| + | |||
| + | In the example, we've added two child elements called '' | ||
| + | |||
| + | **NOTE**: To save a document using the write method, we need to have an '' | ||
| + | |||
| + | <code python> | ||