def add_starttag(self, tag, ident = 0, attribs = '', text = '', close = False):
'''
Add a starttag with optional attributestring, textstring and optionally close it.
Give it the proper ident.
'''
if isinstance(attribs, dict):
a = ''
for k, v in attribs.items():
a = '%s %s=%s' % (a, k, saxutils.quoteattr(v))
attribs = a
if attribs != '':
attribs = ' %s' % attribs
if close and text == '':
return u'%s<%s%s/>\n' % (''.rjust(ident), self.xmlescape(tag), attribs)
if close and text != '':
return u'%s<%s%s>%s</%s>\n' % (''.rjust(ident), self.xmlescape(tag), attribs, self.xmlescape(text), self.xmlescape(tag))
else:
return u'%s<%s%s>%s\n' % (''.rjust(ident), self.xmlescape(tag), attribs, self.xmlescape(text))
评论列表
文章目录