def ContentsAsXml(self, indent, one_line): '''Returns the contents of this node (CDATA and child elements) in XML format. If 'one_line' is true, the content will be laid out on one line.''' assert isinstance(indent, types.StringTypes) # Build the contents of the element. inside_parts = [] last_item = None for mixed_item in self.mixed_content: if isinstance(mixed_item, Node): inside_parts.append( mixed_item.FormatXml(indent + u' ', one_line)) if not one_line: inside_parts.append(u'\n') else: message = mixed_item # If this is the first item and it starts with whitespace, we add # the ''' delimiter. if not last_item and message.lstrip() != message: message = u"'''" + message inside_parts.append(util.EncodeCdata(message)) last_item = mixed_item # If there are only child nodes and no cdata, there will be a spurious # trailing \n if len(inside_parts) and inside_parts[-1] == '\n': inside_parts = inside_parts[:-1] # If the last item is a string (not a node) and ends with whitespace, # we need to add the ''' delimiter. if (isinstance(last_item, types.StringTypes) and last_item.rstrip() != last_item): inside_parts[-1] = inside_parts[-1] + u"'''" return u''.join(inside_parts)
def Escape(self, text): return util.EncodeCdata(text)