An open API service indexing awesome lists of open source software.

https://github.com/dev360/fooxml

XML parsing foo made simpler
https://github.com/dev360/fooxml

Last synced: 15 days ago
JSON representation

XML parsing foo made simpler

Awesome Lists containing this project

README

          

fooxml
======

## XML file too big? Python XML parsing got you down?

fooxml uses sax/pull XML parsing and allows you to parse multi
giga-byte files efficiently with less code.

**Code, k thx bai:**

```python
from StringIO import StringIO
import fooxml

# From http://www.w3schools.com/xml/simple.xml
xml_fragment = """


Belgian Waffles
$5.95
two of our famous Belgian Waffles with plenty of real maple syrup
650


Strawberry Belgian Waffles
$7.95
light Belgian waffles covered with strawberries and whipped cream
900

"""
stream = StringIO(xml_fragment)
stream.seek(0)

def callback(obj):
print "{0},{1},{2}".format(obj['name'], obj['price'], obj['calories'])

handler = fooxml.SimpleHandler("food", callback=callback)
xml_file = fooxml.xml_file(stream, handler)
xml_file.parse()

# Outputs:
# Belgian Waffles,$5.95,650
# Strawberry Belgian Waffles,$7.95,900

```

This is pretty barebones - adding more functionality as use cases emerge.