Skip to main content

A modern refactoring of the venerable xmltramp application

Project description

# xmltramp2

[xmltramp]( was originally created by Aaron Swartz
for simple-yet-powerful parsing of RSS and other xml files.

It is a simple, fast, lightweight alternative to more heavyweight parsers such as BeautifulSoup or ElementTree. It won't do all they do, but what it does do it does simply and easily.

It has been substantially rewritten for subsequent python versions,
including Python3 compatibility. Tests are included.

## Installation

The easiest way is via pip:

`pip install xmltramp2`

Usage is unchanged from older versions of xmltramp, other than you now import from a package:

`from xmltramp2 import xmltramp`

## Usage

Everyone's got their data in XML these days. You need to read it. You've looked at the other XML APIs and they all contain miles of crud that's only necessary when parsing the most arcane documents. Wouldn't it be nice to have an easy-to-use API for the normal XML documents you deal with? That's xmltramp:

>>> sample_xml = """<doc version="2.7182818284590451"
<author><name>John Polk</name> and <name>John Palfrey</name></author>
<dc:creator>John Polk</dc:creator>
<dc:creator>John Palfrey</dc:creator>
<bbc:show bbc:station="4">Buffy</bbc:show>

>>> import xmltramp
>>> doc = xmltramp.Namespace("")
>>> bbc = xmltramp.Namespace("")
>>> dc = xmltramp.Namespace("")
>>> d = xmltramp.parse(sample_xml)
>>> d
<doc version="2.7182818284590451">...</doc>
>>> d('version')
>>> d(version='2.0')
>>> d('version')
>>> d._dir
[<author>...</author>, <dc:creator>...</dc:creator>, <dc:creator>...</dc:creator>, <bbc:show bbc:station="4">...</bbc:show>]
>>> d._name
(u'', u'doc')
>>> d[0] # First child.
>>> # First author.
>>> str(
'John Polk and John Palfrey'
>>> d[dc.creator] # First dc:creator.
>>> d[dc.creator:] # All creators.
[<dc:creator>...</dc:creator>, <dc:creator>...</dc:creator>]
>>> d[dc.creator] = "Me!!!"
>>> str(d[dc.creator])
>>> d[](bbc.station)
>>> d[](bbc.station, '5')
>>> d[](bbc.station)


## Credits

Most thanks go to Aaron Swartz, both for writing this in the first place, and just in general, for all he did.

Additional thanks to Kristian Glass, for helping get this over the Python3 hump, and for tests.

Project details

Download files

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

Source Distribution

xmltramp2-3.0.10.tar.gz (6.5 kB view hashes)

Uploaded source

Supported by

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