magictree 1.0.0
Easily create ElementTree with automatic Element factories
Creating tree structures like those used for HTML and XML should be dead easy. The xml.etree.ElementTree library goes quite far in creating a simple to use library for creating and modifying such structures. I'd like to go a step further, building on top of ElementTree:
from magictree import html, head, title, body, h1, p
doc = html(
head(
title('Chapter 1: Greeting')),
body(
h1('Chapter 1: Greeting'),
p('Hello, world!')))
from xml.etree import ElementTree as et
et.dump(doc)
Results in this: (added some whitespace for formatting)
<html>
<head>
<title>Chapter 1: Greeting</title>
</head>
<body>
<h1>Chapter 1: Greeting</h1>
<p>Hello, world!</p>
</body>
</html>
This works by replacing this module with a wrapper object in sys.modules that creates factory functions for elements based on their name.
I used this page as a basis for the hack: http://stackoverflow.com/questions/2447353/getattr-on-a-module
| File | Type | Py Version | Uploaded on | Size | # downloads |
|---|---|---|---|---|---|
| magictree-1.0.0.win32.exe (md5) | MS Windows installer | any | 2011-07-06 | 63KB | 135 |
| magictree-1.0.0.zip (md5) | Source | 2011-07-06 | 3KB | 216 | |
- Author: Daren Thomas
- Home Page: http://code.google.com/p/pymagictree/
-
Categories
- Development Status :: 3 - Alpha
- Intended Audience :: Developers
- License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
- Operating System :: OS Independent
- Programming Language :: Python
- Programming Language :: Python :: 2.5
- Topic :: Text Processing :: Markup :: HTML
- Topic :: Text Processing :: Markup :: XML
- Package Index Owner: DarenThomas
- DOAP record: magictree-1.0.0.xml
