mirror of
https://github.com/kennethreitz/python-guide.git
synced 2026-06-05 23:00:18 +00:00
Merge pull request #137 from stchris/master
Scenario "XML parsing" + lib "untangle"
This commit is contained in:
@@ -54,6 +54,7 @@ different scenarios.
|
|||||||
scenarios/speed
|
scenarios/speed
|
||||||
scenarios/scientific
|
scenarios/scientific
|
||||||
scenarios/imaging
|
scenarios/imaging
|
||||||
|
scenarios/xml
|
||||||
|
|
||||||
|
|
||||||
Shipping Great Code
|
Shipping Great Code
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
XML parsing
|
||||||
|
===========
|
||||||
|
|
||||||
|
untangle
|
||||||
|
--------
|
||||||
|
|
||||||
|
`untangle <http://0chris.com/untangle>`_ is a simple library which takes
|
||||||
|
an XML document and returns a Python object which mirrors the nodes and
|
||||||
|
attributes in its structure.
|
||||||
|
|
||||||
|
For example, an xml file like this:
|
||||||
|
|
||||||
|
.. code-block:: xml
|
||||||
|
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<root>
|
||||||
|
<child name="child1">
|
||||||
|
</root>
|
||||||
|
|
||||||
|
can be loaded like this:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
import untangle
|
||||||
|
obj = untangle.parse('path/to/file.xml')
|
||||||
|
|
||||||
|
and then you can get the child elements name like this:
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
obj.root.child['name']
|
||||||
|
|
||||||
|
untangle also supports loading XML from a string or an URL.
|
||||||
|
|
||||||
Reference in New Issue
Block a user