Skip to main content

UNKNOWN

Project description

Converts XML to Python objects.

Installation

pip install unwind

Example

We have following XML file and we desire to parse it:

<?xml version="1.0" encoding="UTF-8"?>
<page>
    <menu>
        <name aaa="bbb" ccc="ddd">Привет мир</name>
        <items>
            <item>
                <name rel="lala">Пункт 1</name>
                <url>http://example1.com</url>
            </item>
            <item>
                <name>Пункт 2</name>
                <url>http://example2.com</url>
            </item>
        </items>
    </menu>
    <spec-sy.mbols>Символы</spec-sy.mbols>

</page>

In Python:

Load XML from file:

>>> import unwind
>>> page = unwind.parse("example.xml")

Load XML from string:

>>> xml = """
        <?xml version="1.0" encoding="UTF-8"?>
        <root />
    """
>>> page = unwind.fromstring(xml)

Get some text:

>>> page.menu.name.get_text()

Get some attrs:

>>> page.menu.name['aaa']
>>> page.menu.name['ccc']

Get list:

>>> page.menu.items.get_children()

Iterate through a list:

>>> for item in page.menu.items:
>>>     print item.name.get_text()

Project details


Release history Release notifications

This version
History Node

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
unwind-0.1.tar.gz (2.2 kB) Copy SHA256 hash SHA256 Source None Mar 24, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page