Get a string representation of this XML fragment. @param indent: The indent to be used in formatting the output. @type indent: int @return: A I{pretty} string. @rtype: basestring
(self, indent=0)
| 741 | self.nsprefixes[ns[0]] = ns[1] |
| 742 | |
| 743 | def str(self, indent=0): |
| 744 | """ |
| 745 | Get a string representation of this XML fragment. |
| 746 | @param indent: The indent to be used in formatting the output. |
| 747 | @type indent: int |
| 748 | @return: A I{pretty} string. |
| 749 | @rtype: basestring |
| 750 | """ |
| 751 | tab = '%*s' % (indent * 3, '') |
| 752 | result = [] |
| 753 | result.append('%s<%s' % (tab, self.qname())) |
| 754 | result.append(self.nsdeclarations()) |
| 755 | for a in [unicode(a) for a in self.attributes]: |
| 756 | result.append(' %s' % a) |
| 757 | if self.isempty(): |
| 758 | result.append('/>') |
| 759 | return ''.join(result) |
| 760 | result.append('>') |
| 761 | if self.hasText(): |
| 762 | result.append(self.text.escape()) |
| 763 | for c in self.children: |
| 764 | result.append('\n') |
| 765 | result.append(c.str(indent+1)) |
| 766 | if len(self.children): |
| 767 | result.append('\n%s' % tab) |
| 768 | result.append('</%s>' % self.qname()) |
| 769 | result = ''.join(result) |
| 770 | return result |
| 771 | |
| 772 | def plain(self): |
| 773 | """ |