Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

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 | RSS feed

This version

0.1

Download files

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

Files for unwind, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size unwind-0.1.tar.gz (2.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page