xmlgenerator /

Filename Size Date modified Message
1.1 KB
4.3 KB

xmlgenerator.py

xmlgenerator.py is a simple unicode XML Generator made in python.

Usage:

>>> from xmlgenerator import Xml, Node

Node creation

>>> root = Node('root')
>>> records = Node('blog', 'http://mariz.org', dict(author='Nuno Mariz', title='Nuno Mariz Weblog'))

Append a child node

>>> root.append(records)
>>> root
<Node: "root">
>>> root.render()
u'<root><blog author="Nuno Mariz" title="Nuno Mariz Weblog">http://mariz.org</blog></root>'

Xml document creation

>>> xml = Xml(root)
>>> xml.render()
u'<?xml version="1.0" encoding="utf-8"?>\n
<root><blog author="Nuno Mariz" title="Nuno Mariz Weblog">http://mariz.org</blog></root>'

Writing contents to a file or a writer

>>> import cStringIO
>>> output = cStringIO.StringIO()
>>> xml = Xml(root)
>>> xml.render(output)
>>> print output.getvalue()
<?xml version="1.0" encoding="utf-8"?>
<root><blog author="Nuno Mariz" title="Nuno Mariz Weblog">http://mariz.org</blog></root>
>>> output.close()
>>> # Writing contents to a file
>>> xml = Xml(root)
>>> xml.write('blogs.xml')

Changing the global Xml encoding

>>> Xml.encoding = 'iso-8859-1' # The default is utf-8
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.