1. Mathias Panzenböck
  2. Python XmlMarkup

Wiki

Clone wiki

Python XmlMarkup / Home

Big demo: demo.py

from __future__ import with_statement
from XmlMarkup  import *
import sys

with XmlMarkup(sys.stdout) as xm:
	with xm.root():
		xm.text('foo')
		with xm.prefixMapping(x='http://example.com/x'):
			with xm.tag(xmlns='http://example.com/x'):
				xm.comment('comment')
			with xm('text'):
				xm.text('bar')
		with xm.tag(foo='bar',egg='spam'):
			pass
	xm.text('\n')

Output:

<?xml version="1.0" encoding="utf-8"?>
<root>foo<x:tag xmlns:x="http://example.com/x"><!--comment--></x:tag><text>bar</text><tag foo="bar" egg="spam"></tag></root>

Updated