Skip to content

Commit c1a57ae

Browse files
author
Kenneth Reitz
committed
Merge pull request realpython#137 from stchris/master
Scenario "XML parsing" + lib "untangle"
2 parents 2c91b8e + 9b8752b commit c1a57ae

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

docs/contents.rst.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ different scenarios.
5454
scenarios/speed
5555
scenarios/scientific
5656
scenarios/imaging
57+
scenarios/xml
5758

5859

5960
Shipping Great Code

docs/scenarios/xml.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
XML parsing
2+
===========
3+
4+
untangle
5+
--------
6+
7+
`untangle <http://0chris.com/untangle>`_ is a simple library which takes
8+
an XML document and returns a Python object which mirrors the nodes and
9+
attributes in its structure.
10+
11+
For example, an xml file like this:
12+
13+
.. code-block:: xml
14+
15+
<?xml version="1.0"?>
16+
<root>
17+
<child name="child1">
18+
</root>
19+
20+
can be loaded like this:
21+
22+
.. code-block:: python
23+
24+
import untangle
25+
obj = untangle.parse('path/to/file.xml')
26+
27+
and then you can get the child elements name like this:
28+
29+
.. code-block:: python
30+
31+
obj.root.child['name']
32+
33+
untangle also supports loading XML from a string or an URL.
34+

0 commit comments

Comments
 (0)