Convert to XML-Document and return it as string
336965
def to_s(*)
      doc = REXML::Document.new
      decl = REXML::XMLDecl.new("1.0", "utf-8")
      doc.add decl
      doc.add_element @elem
      doc.to_s
    end
452383
def to_xml(value, options = {})
      if value.is_a?(Exchanger::Element)
        value.tag_name = tag_name
        value.to_xml(options)
      else
        doc = Nokogiri::XML::Document.new
        root = doc.create_element(tag_name)
        case value
        when Array
          value.each do |sub_value|
            root << sub_field.to_xml(sub_value, options)
          end
        when Boolean
          root << doc.create_text_node(value == true)
        when Time
          root << doc.create_text_node(value.xmlschema)
        else # String, Integer, etc
          root << doc.create_text_node(value.to_s)
        end
        root
      end
    end
953953
def to_xml(self):
        '''
        
        '''
        for n, v in { "amount": self.amount, "date": self.date,
                     "method":self.method}.items():
            if is_empty_or_none(v):
                raise PaymentError("'%s' attribute cannot be empty or " \
                                       "None." % n)

        doc = Document()
        root = doc.createElement("payment")
        super(Payment, self).to_xml(root)
        self._create_text_node(root, "amount", self.amount)
        self._create_text_node(root, "method", self.method)
        self._create_text_node(root, "reference", self.ref, True)
        self._create_text_node(root, "date", self.date)
        return root
981767
public static String xmlToString(Document document) throws Exception {
        if (transformer == null) {
            throw new Exception("Transformer is null");
        }
        Source xmlSource = new DOMSource(document);
        StringWriter stringWriter = new StringWriter();
        Result result = new StreamResult(stringWriter);
        transformer.transform(xmlSource, result);
        return stringWriter.toString();
    }
1363815
def asXML( self, doctag=None, namedItemsOnly=False, indent="", formatted=True ):
        
        nl = "\n"
        out = []
        namedItems = dict((v[1],k) for (k,vlist) in self.__tokdict.items()
                                                            for v in vlist)
        nextLevelIndent = indent + "  "

        # collapse out indents if formatting is not desired
        if not formatted:
            indent = ""
            nextLevelIndent = ""
            nl = ""

        selfTag = None
        if doctag is not None:
            selfTag = doctag
        else:
            if self.__name:
                selfTag = self.__name

        if not selfTag:
            if namedItemsOnly:
                return ""
            else:
                selfTag = "ITEM"

        out += [ nl, indent, "<", selfTag, ">" ]

        for i,res in enumerate(self.__toklist):
            if isinstance(res,ParseResults):
                if i in namedItems:
                    out += [ res.asXML(namedItems[i],
                                        namedItemsOnly and doctag is None,
                                        nextLevelIndent,
                                        formatted)]
                else:
                    out += [ res.asXML(None,
                                        namedItemsOnly and doctag is None,
                                        nextLevelIndent,
                                        formatted)]
            else:
                # individual token, see if there is a name for it
                resTag = None
                if i in namedItems:
                    resTag = namedItems[i]
                if not resTag:
                    if namedItemsOnly:
                        continue
                    else:
                        resTag = "ITEM"
                xmlBodyText = _xml_escape(_ustr(res))
                out += [ nl, nextLevelIndent, "<", resTag, ">",
                                                xmlBodyText,
                                                "</", resTag, ">" ]

        out += [ nl, indent, "</", selfTag, ">" ]
        return "".join(out)
47545
def to_xml_string(str = '')
      str << '<sheetViews>'
      str << '<sheetView '
      serialized_attributes str
      str << '>'
      @pane.to_xml_string(str) if @pane
      @selections.each do |key, selection|
        selection.to_xml_string(str)
      end
      str << '</sheetView>'
      str << '</sheetViews>'
    end
1046189
def xmlstring(self, pretty_print=False):
        """"""
        s = ElementTree.tostring(self.xml(), xml_declaration=False, pretty_print=pretty_print, encoding='utf-8')
        if sys.version < '3':
            if isinstance(s, str):
                s = unicode(s,'utf-8') #pylint: disable=undefined-variable
        else:
            if isinstance(s,bytes):
                s = str(s,'utf-8')

        s = s.replace('ns0:','') #ugly patch to get rid of namespace prefix
        s = s.replace(':ns0','')
        return s
1173693
def tostring(self):
        """"""
        parser = etree.XMLParser(remove_blank_text=True)
        outputtree = etree.XML(etree.tostring(self.__doc), parser)
        return etree.tostring(outputtree, pretty_print=True)
1171919
def toxml(self):
        

        xmlstr = '<OnEvent port="{0}"'.format(self.port)

        chxmlstr = ''

        for action in self.actions:
            chxmlstr += action.toxml()

        if chxmlstr:
            xmlstr += '>' + chxmlstr + '</OnEvent>'
        else:
            xmlstr += '/>'

        return xmlstr
1056649
def to_xml_string(str = "")
      str << ('<c:' << @tag_name.to_s << '>')
      str << ('<c:formatCode>' << format_code.to_s << '</c:formatCode>')
      str << ('<c:ptCount val="' << @pt.size.to_s << '"/>')
      @pt.each_with_index do |num_val, index|
        num_val.to_xml_string index, str
      end
      str << ('</c:' << @tag_name.to_s << '>')
    end
681284
def to_xml(self):
        '''
        
        '''
        if not len(self.lines):
            raise GroupError("A group must at least have one line.")

        doc = Document()
        root = doc.createElement("group")
        super(Group, self).to_xml(root)
        self._create_text_node(root, "name", self.name, True)
        self._create_text_node(root, "description", self.description, True)

        lines = doc.createElement("lines")
        root.appendChild(lines)
        for line in self.__lines:
            if not issubclass(line.__class__, Line):
                raise GroupError('line of type %s is not an instance ' \
                                     'or a subclass of %s' %
                                     (line.__class__.__name__, Line.__name__))
            lines.appendChild(line.to_xml())

        return root
1092612
def to_xml(body_element):
    
    doctype = b"""<?xml version="1.0" encoding="UTF-8"?>\n"""
    if body_element is None:
        return succeed(b"")
    d = flattenString(None, body_element)
    d.addCallback(lambda flattened: doctype + flattened)
    return d
1157885
def element_to_string(element, include_declaration=True, encoding=DEFAULT_ENCODING, method='xml'):
    

    if isinstance(element, ElementTree):
        element = element.getroot()
    elif not isinstance(element, ElementType):
        element = get_element(element)

    if element is None:
        return u''

    element_as_string = tostring(element, encoding, method).decode(encoding=encoding)
    if include_declaration:
        return element_as_string
    else:
        return strip_xml_declaration(element_as_string)
1335374
def to_xml_string(str="")
      str << ('<c:' << tag_name.to_s << '>')
      if @f
        str << ('<c:' << @ref_tag_name.to_s << '>')
        str << ('<c:f>' << @f.to_s << '</c:f>')
      end
      @data.to_xml_string str
      if @f
        str << ('</c:' << @ref_tag_name.to_s << '>')
      end
      str << ('</c:' << tag_name.to_s << '>')
    end
920030
def toxml(self):
        

        xmlstr = '<OnStart'

        chxmlstr = ''

        for action in self.actions:
            chxmlstr += action.toxml()

        if chxmlstr:
            xmlstr += '>' + chxmlstr + '</OnStart>'
        else:
            xmlstr += '/>'

        return xmlstr
492068
def to_xml_string(str = '')
      str << '<?xml version="1.0" encoding="UTF-8"?>'
      str << ('<pivotCacheDefinition xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '" invalid="1" refreshOnLoad="1" recordCount="0">')
      str <<   '<cacheSource type="worksheet">'
      str << (    '<worksheetSource ref="' << pivot_table.range << '" sheet="' << pivot_table.data_sheet.name << '"/>')
      str <<   '</cacheSource>'
      str << (  '<cacheFields count="' << pivot_table.header_cells_count.to_s << '">')
      pivot_table.header_cells.each do |cell|
        str << (  '<cacheField name="' << cell.value << '" numFmtId="0">')
        str <<     '<sharedItems count="0">'
        str <<     '</sharedItems>'
        str <<   '</cacheField>'
      end
      str <<   '</cacheFields>'
      str << '</pivotCacheDefinition>'
    end
749644
function to_xml(){
		$str="<action type='{$this->status}' sid='{$this->id}' tid='{$this->nid}' ";
		foreach ($this->attrs as $k => $v) {
			$str.=$k."='".$this->xmlentities($v)."' ";
		}
		$str.=">{$this->output}</action>";	
		return $str;
	}