XML is also frequently written by non-programmers. Mixing logic and XML may force non-programmers to acquire a programming awareness that may be counterproductive
to their jobs. They might also be forced to wait for a programmer to
change the data format before they can work on it (and vice versa).
XML is for data. Python is for logic.
Q: But isn't tag-soup like HTML 4 evil?
A: No. HTML 4.01 isn't XML but it's the best option for serving pages at present because all browsers have relatively strong support for it. Serving XHTML as text/html has serious issues and not all browsers (IE <= 7.0) support XHTML as application/xhtml+xml.However, maintaining content in an XML based format is advantageous because you can perform validation, transformations, and other stuff using readily available tools. It's possible to have the best of both worlds: HTML 4.01 for the browser and XHTML (or some custom XML format) for the server.
Some of us still believe that XHTML will eventually be supported well, and that when it does, it will be the way to go. You should be able to "flip a switch, make it work" when that day comes instead of doing a massive migration.
webstring's HTMLTemplate class handles this transition from the past to the future seamlessly. It can take even horribly broken HTML and output it as HTML 4.01, XHTML 1.0, or XHTML 1.1 depending upon a developer's needs.
easy_install webstring
>>> from webstring import Template
>>> exampleA = Template()
>>> exampleB.fromfile('example.rss')
>>> exampleC = Template('example.rss')
>>> exampleD = Template().fromstring("""<rss version="2.0">
... <channel>
... <title>Example</title>
... <link>http://www.example.org/</link>
... <description>RSS Example</description>
... <language>en-us</language>
... <pubDate id="cpubdate">$month $day, $year</pubDate>
... <lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate> ... <item class="item">
... <title id="title" />
... <link id="link" />
... <guid id="guid" isPermaLink="true" />
... <description id="description" />
... <pubDate id="ipubdate" />
... </item>
... </channel>
... </rss>""")
>>> example = Template("""<rss version="2.0">
... <channel>
... <title>Example</title>
... <link>http://www.example.org/</link>
... <description>RSS Example</description>
... <language>en-us</language>
... <pubDate id="cpubdate">$month $day, $year</pubDate>
... <lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate> ... <item class="item">
... <title id="title" />
... <link id="link" />
... <guid id="guid" isPermaLink="true" />
... <description id="description" />
... <pubDate id="ipubdate" />
... </item>
... </channel>
... </rss>""")
>>> example = Template(engine="lxml")
>>> example = Template(format="html", engine="lxml")
>>> example = Template(format="html", engine="lxml")
<pubDate id="cpubdate">$month $day, $year</pubDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
>>> example
<Template "root" at db7dd0>
>>> example.item
<Template "item" at f5d870>
>>> example.item.guid
<Template "guid" at f5da70>
>>> example.item.guid.isPermaLink
'true'
>>> example
<Template "root" at db7dd0>
>>> example.cpubdate
<Template "cpubdate" at e7a350>
>>> example.exclude('cpubdate', 'guid')
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.include('cpubdate', 'guid')
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate> <item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> del example.cpubdate
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.reset()
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.cpubdate
<Template "cpubdate" at e7a350>
>>> example['cpubdate']
<Template "cpubdate" at e7a350>
>>> example[0]
<Template "cpubdate" at e7a350>
>>> example.item
<Template "item" at f5d870>
>>> example['item']
<Template "item" at f5d870>
>>> example[2]
<Template "item" at f5d870>
>>> example.item.title
<Template "title" at f5d9b0>
>>> example['item']['title']
<Template "title" at f5d9b0>
>>> example[2][0]
<Template "title" at f5d9b0>
>>> example.item.guid.isPermaLink
'true'
>>> example['item']['guid']['isPermaLink']
'true'
>>> exampleZ = Template('example.rss', False)
>>> example.item.description.text = 'Example of assigning text to a field.' >>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
<pubDate id="cpubdate">$month $day, $year</pubDate>
>>> example.cpubdate.text = {'month':'June', 'day':'06', 'year':'2006'}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
>>> example.lastbuilddate.text = {'month':'June', 'day':'06', 'year':'2006'}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.cpubdate.template
<string.Template object at 0x00F81F70>
>>> example.lastbuilddate.template
%(month)s %(day)s, %(year)s
>>> example.item.link.template = 'http://www.example.org/rss/$id'
>>> example.item.link.template
<string.Template object at 0x00DB7E70>
>>> example.item.link.text = {'id':'5423093'}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="true" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.item.templates({'title':{'text':'Example Title: $content'}, ... 'ipubdate':{'text':'$month $day, $year'}})
>>> example.item.title.template
<string.Template object at 0x00EA75B0>
>>> example.item.ipubdate.template
<string.Template object at 0x00EA7690>
>>> example.item.title.text = {'content':'First Example'}
>>> example.item.ipubdate.text = {'month':'June', 'day':'6', 'year':'2006'}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="true" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.item.guid.isPermaLink = 'false'
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="false" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.item.guid.update({'isPermaLink':'true', 'id':'GUID', ... '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource':'http://www.example.org/rss/5423093'})
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="GUID" isPermaLink="true" rdf:resource="http://www.example.org/rss/5423093" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.item.guid.atemplates = { ... '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource':'http://www.example.org/rss/$guid'}
>>> example.item.guid.update({ ... '{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource':{'guid':'5423094'}})
>>> example.item.guid.resource = {'guid':'5423093'}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="GUID" isPermaLink="true" rdf:resource="http://www.example.org/rss/5423093" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.item.guid.purge('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource')
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="GUID" isPermaLink="true" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.item.guid.update( ... {'{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource':'http://www.example.org/rss/5423093'})
>>> del example.item.guid.resource
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="false" />
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.reset()
>>> example.cpubdate %= {'text':{'month':'June', 'day':'06', 'year':'2006'}}
>>> example.lastbuilddate %= {'text':{'month':'June', 'day':'06', 'year':'2006'}}
>>> example.item %= {
... 'templates':{
... 'title':{'text':'Example Title: $content'},
... 'ipubdate':{'text':'$month $day, $year'},
... 'link':{'text':'http://www.example.org/rss/$id'}},
... 'subs':((
... {'text':{'content':'First Example'}},
... {'text':{'id':'5423093'}}, {'attrib':{'id':'GUID'}},
... {'text':'http://www.example.org/rss/5423093'},
... 'Example of assigning text to a field.',
... {'text':{'month':'June', 'day':'6', 'year':'2006'}}),)}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="GUID" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example %= {
... 'cpubdate':{'text':{'month':'June', 'day':'06', 'year':'2006'}},
... 'lastbuilddate':{'text':{'month':'June', 'day':'06', 'year':'2006'}},
... 'item':{'templates':{'title':{'text':'Example Title: $content'}, ... 'ipubdate':{'text':'$month $day, $year'},
... 'link':{'text':'http://www.example.org/rss/$id'}},
... 'title':{'text':{'content':'First Example'}},
... 'link':{'text':{'id':'5423093'}},
... 'guid':{'attrib':{'id':'GUID'}, 'text':'http://www.example.org/rss/5423093'},
... 'description':{'text':'Example of assigning text to a field.'},
... 'ipubdate':{'text':{'month':'June', 'day':'6', 'year':'2006'}}}}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="GUID" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.current
<Template "root" at dcd290>
>>> print example.current
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="GUID" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 6, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.default
<Template "root" at f62d10>
>>> print example.default
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.reset()
>>> print example + example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
<rss version="2.0"> <channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel> </rss></rss>
>>> print example.item + example.item
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
>>> print example.item.title + example.item.title
<title id="title" />
<title id="title" />
>>> example.item += example.item
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.reset()
>>> example.item.repeat()
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item> <item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.reset()
>>> example.item *= 2
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>
>>> example.reset()
>>> example.item %= ( ... 'Example Title: First Example', ... 'http://www.example.org/rss/5423092', ... 'http://www.example.org/rss/5423092', ... 'Example of assigning text to a field.', ... 'June 06, 2006')
>>> example.item.repeat(( ... 'Example Title: Second Example', ... 'http://www.example.org/rss/5423093', ... 'http://www.example.org/rss/5423093', ... 'Example of group repetition.', ... 'June 06, 2006'))
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423092</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
<item class="item">
<title id="title">Example Title: Second Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of group repetition.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.reset()
>>> example.item **= (( ... 'Example Title: First Example', ... 'http://www.example.org/rss/5423092', ... 'http://www.example.org/rss/5423092', ... 'Example of assigning text to a field.', ... 'June 06, 2006'), ( ... 'Example Title: Second Example', ... 'http://www.example.org/rss/5423093', ... 'http://www.example.org/rss/5423093', ... 'Example of group repetition.', ... 'June 06, 2006'))
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423092</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
<item class="item">
<title id="title">Example Title: Second Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of group repetition.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.reset()
>>> example.item %= { ... 'templates':{ ... 'title':{'text':'Example Title: $content'}, ... 'ipubdate':{'text':'$month $day, $year'}, ... 'link':{'text':'http://www.example.org/rss/$id'}},
... 'subs':( ... ({'text':{'content':'First Example'}}, ... {'text':{'id':'5423092'}}, ... 'http://www.example.org/rss/5423092',
... 'Example of assigning text to a field.', ... {'text':{'year':'June', 'day':'06', 'year':'2006'}}),
... ({'text':{'content':'Second Example'}}, ... {'text':{'id':'5423093'}}, ... 'http://www.example.org/rss/5423093',
... 'Example of group repetition.', ... {'text':{'month':'June', 'day':'06', 'year':'2006'}}))}
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423092</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description id="description">Example of assigning text to a field.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
<item class="item">
<title id="title">Example Title: Second Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of group repetition.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.reset()
>>> example.max = 1
>>> example.item %= { ... 'templates':{ ... 'title':{'text':'Example Title: $content'}, ... 'ipubdate':{'text':'$month $day, $year'}, ... 'link':{'text':'http://www.example.org/rss/$id'}},
... 'subs':( ... ({'text':{'content':'First Example'}}, ... {'text':{'id':'5423092'}}, ... 'http://www.example.org/rss/5423092',
... 'Example of assigning text to a field.', ... {'text':{'year':'June', 'day':'06', 'year':'2006'}}),
... ({'text':{'content':'Second Example'}}, ... {'text':{'id':'5423093'}}, ... 'http://www.example.org/rss/5423093',
... 'Example of group repetition.', ... {'text':{'month':'June', 'day':'06', 'year':'2006'}}))}
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "webstring.py", line 641, in __imod__
self.__ipow__(data.pop('subs'))
File "webstring.py", line 276, in __ipow__
raise TypeError(_exceptions[0])
TypeError: maximum allowed repetitions exceeded
>>> example.reset()
>>> example.max = 1
>>> example.item %= { ... 'templates':{ ... 'title':{'text':'Example Title: $content'}, ... 'ipubdate':{'text':'$month $day, $year'}, ... 'link':{'text':'http://www.example.org/rss/$id'}},
... 'subs':( ... ({'text':{'content':'First Example'}}, ... {'text':{'id':'5423092'}}, ... 'http://www.example.org/rss/5423092',
... 'Example of assigning text to a field.', ... {'text':{'year':'June', 'day':'06', 'year':'2006'}}),
... ({'text':{'content':'Second Example'}}, ... {'text':{'id':'5423093'}}, ... 'http://www.example.org/rss/5423093',
... 'Example of group repetition.', ... {'text':{'month':'June', 'day':'06', 'year':'2006'}}))}
>>>
>>> example.reset()
>>> example.cpubdate %= {'text':{'month':'June', 'day':'06', 'year':'2006'}}
>>> example.lastbuilddate %= {'text':{'month':'June', 'day':'06', 'year':'2006'}}
>>> example.item %= { ... 'templates':{ ... 'title':{'text':'Example Title: $content'}, ... 'ipubdate':{'text':'$month $day, $year'}, ... 'link':{'text':'http://www.example.org/rss/$id'}},
... 'subs':( ... ({'text':{'content':'First Example'}}, ... {'text':{'id':'5423092'}}, ... 'http://www.example.org/rss/5423092',
... 'Example of assigning text to a field.', ... {'text':{'year':'June', 'day':'06', 'year':'2006'}}),
... ({'text':{'content':'Second Example'}}, ... {'text':{'id':'5423093'}}, ... 'http://www.example.org/rss/5423093',
... 'Example of group repetition.', ... {'text':{'month':'June', 'day':'06', 'year':'2006'}}))}
>>> example.item.description.append(Template( ... '<html><head><title>Example</title></head><body><p>Paragraph</p></body></html>'))
>>> del example.item.description.text
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">June 06, 2006</pubDate>
<lastBuildDate id="lastbuilddate">June 06, 2006</lastBuildDate>
<item class="item">
<title id="title">Example Title: First Example</title>
<link id="link">http://www.example.org/rss/5423092</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description id="description"><html><head><title>Example</title></head><body><p>Paragraph</p></body></html></description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
<item class="item">
<title id="title">Example Title: Second Example</title>
<link id="link">http://www.example.org/rss/5423093</link>
<guid id="guid" isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description id="description">Example of group repetition.</description>
<pubDate id="ipubdate">June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> for field in example: field.__repr__()
...
'<Template "cpubdate" at f62f50>'
'<Template "lastbuilddate" at e7a350>'
'<Template "item" at f627f0>'
>>> for attr in example.item.guid: print attr.__repr__()
...
'isPermaLink'
'id'
>>> del example.mark
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate>June 06, 2006</pubDate>
<lastBuildDate>June 06, 2006</lastBuildDate>
<item class="item">
<title>Example Title: First Example</title>
<link>http://www.example.org/rss/5423092</link>
<guid isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description><html><head><title>Example</title></head><body><p>Paragraph</p></body></html></description>
<pubDate>June 06, 2006</pubDate>
</item>
<item class="item">
<title>Example Title: Second Example</title>
<link>http://www.example.org/rss/5423093</link>
<guid isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description>Example of group repetition.</description>
<pubDate>June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> del example.groupmark
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate>June 06, 2006</pubDate>
<lastBuildDate>June 06, 2006</lastBuildDate>
<item>
<title>Example Title: First Example</title>
<link>http://www.example.org/rss/5423092</link>
<guid isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description><html><head><title>Example</title></head><body><p>Paragraph</p></body></html></description>
<pubDate>June 06, 2006</pubDate>
</item>
<item>
<title>Example Title: Second Example</title>
<link>http://www.example.org/rss/5423093</link>
<guid isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description>Example of group repetition.</description>
<pubDate>June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> print example.render()
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate>June 06, 2006</pubDate>
<lastBuildDate>June 06, 2006</lastBuildDate>
<item>
<title>Example Title: First Example</title>
<link>http://www.example.org/rss/5423092</link>
<guid isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description><html><head><title>Example</title></head><body><p>Paragraph</p></body></html></description>
<pubDate>June 06, 2006</pubDate>
</item>
<item>
<title>Example Title: Second Example</title>
<link>http://www.example.org/rss/5423093</link>
<guid isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description>Example of group repetition.</description>
<pubDate>June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> example.write('finalexample.rss')
>>> print example.pipe()
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate>June 06, 2006</pubDate>
<lastBuildDate>June 06, 2006</lastBuildDate>
<item>
<title>Example Title: First Example</title>
<link>http://www.example.org/rss/5423092</link>
<guid isPermaLink="true">http://www.example.org/rss/5423092</guid>
<description><html><head><title>Example</title></head><body><p>Paragraph</p></body></html></description>
<pubDate>June 06, 2006</pubDate>
</item>
<item>
<title>Example Title: Second Example</title>
<link>http://www.example.org/rss/5423093</link>
<guid isPermaLink="true">http://www.example.org/rss/5423093</guid>
<description>Example of group repetition.</description>
<pubDate>June 06, 2006</pubDate>
</item>
</channel>
</rss>
>>> print example
<rss version="2.0">
<channel>
<title>Example</title>
<link>http://www.example.org/</link>
<description>RSS Example</description>
<language>en-us</language>
<pubDate id="cpubdate">$month $day, $year</pubDate>
<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
<item class="item">
<title id="title" />
<link id="link" />
<guid id="guid" isPermaLink="true" />
<description id="description" />
<pubDate id="ipubdate" />
</item>
</channel>
</rss>