Skip to content

Latest commit

 

History

History
21 lines (12 loc) · 593 Bytes

File metadata and controls

21 lines (12 loc) · 593 Bytes

How to read a XML file?

The builtin module xml parses XML files. It contains several XML parsers. They all produce a tree of element objects for each tag that can be searched and allow access to attributes.

The following code parses the XML file :download:`hamlet.xml`:

.. literalinclude:: parse_xml.py

How to write a XML file?

You can create a tree of elements from scratch and write it to a XML file:

.. literalinclude:: write_xml.py

.. seealso::

   `Documentation of the XML module <https://docs.python.org/3/library/xml.html>`__