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
- Host: GitHub
- URL: https://github.com/dev360/fooxml
- Owner: dev360
- Created: 2013-05-01T20:14:54.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-05-03T03:49:41.000Z (about 13 years ago)
- Last Synced: 2025-03-01T00:31:50.839Z (over 1 year ago)
- Language: Python
- Size: 141 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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.