Serialize object ``md_inst`` by transforming it into an
        ``lxml.etree._ElementTree``. If it already is such, return it. If not,
        make sure it is the correct type and return the output of calling
        ``seriaize()`` on it.
338093
def serialize_md_inst(self, md_inst, md_class):
        
        valid_insts = tuple(
            chain((etree._ElementTree, etree._Element), six.string_types)
        )
        if isinstance(md_inst, valid_insts):
            return md_inst
        if not isinstance(md_inst, md_class):
            raise TypeError(
                "Instance {!r} must be instance of {!r}".format(md_inst, md_class)
            )
        return md_inst.serialize()
1205701
def get_pretty_xml(self, encoding='unicode'):
        
        return d1_common.xml.reformat_to_pretty_xml(
            xml.etree.ElementTree.tostring(self._root_el, encoding)
        )
565620
def to_xml(self, name):
        '''
        
        '''
        for n, v in {"rate_type": self.rate_type,
                     "rate": self.rate,
                     "name": self.name,
                     "description": self.description}.items():
            if is_empty_or_none(v):
                raise TreatmentError("'%s' attribute cannot be empty " \
                                         "or None." % n)

        doc = Document()
        root = doc.createElement(name)
        root.setAttribute("type", self.rate_type)
        root.setAttribute("name", to_unicode(self.name))
        root.setAttribute("description", to_unicode(self.description))
        if self.interval:
            root.setAttribute("base", self.interval)
        root.appendChild(doc.createTextNode(to_unicode(self.rate)))
        return root
970848
def get_serialize_format(self, mimetype):
		
		format = self.formats.get(mimetype, None)
		if format is None:
			format = formats.get(mimetype, None)
		return format
912200
def dump(self, obj):
        
        if self.schema_class:
            obj = self.schema_class().dump(obj).data
        else:
            obj = obj['metadata']
        return super(MARCXMLSerializer, self).dump(obj)
838774
def serialize_to_display(self, xslt_url=None):
        
        return d1_common.xml.serialize_to_xml_str(
            self.get_pyxb(), pretty=True, xslt_url=xslt_url
        )
788442
def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw):
        '''
        

        '''
        raise EvaluateException("Unimplemented evaluation", sw.Backtrace(elt))
1087298
def serialize(self, elt, sw, pyobj, name=None, orig=None, **kw):
        '''
        '''
        if pyobj is not None and type(pyobj) not in _seqtypes:
            raise EvaluateException, 'expecting a list or None'

        objid = _get_idstr(pyobj)
        ns,n = self.get_name(name, objid)
        el = elt.createAppendElement(ns, n)
        if self.nillable is True and pyobj is None:
            self.serialize_as_nil(el)
            return None
        
        tc = self.itemTypeCode
        s = StringIO(); sep = ' '
        for item in pyobj:
            s.write(tc.get_formatted_content(item))
            s.write(sep)

        el.createAppendTextNode(s.getvalue())
719391
def _Serialize(self, val, info, defNS):
      
      if not IsChildVersion(self.version, info.version):
         return

      if val is None:
         if info.flags & F_OPTIONAL:
            return
         else:
            raise TypeError('Field "{0}" is not optional'.format(info.name))
      elif isinstance(val, list) and len(val) == 0:
         if info.type is object:
            # Make sure an empty array assigned to Any is typed
            if not isinstance(val, Array):
               raise TypeError('Field "{0}": Cannot assign empty native python array to an Any'.format(info.name))
         elif info.flags & F_OPTIONAL:
            # Skip optional non-Any
            return
         else:
             raise TypeError('Field "{0}" not optional'.format(info.name))

      if self.outermostAttrs:
         attr = self.outermostAttrs
         self.outermostAttrs = None
      else:
         attr = ''
      currDefNS = defNS
      # Emit default ns if tag ns is not the same
      currTagNS = GetWsdlNamespace(info.version)
      if currTagNS != defNS:
         attr += ' xmlns="{0}"'.format(currTagNS)
         currDefNS = currTagNS

      if isinstance(val, DataObject):
         if isinstance(val, MethodFault):
            newVal = LocalizedMethodFault(fault=val, localizedMessage=val.msg)
            if info.type is object:
               faultType = object
            else:
               faultType = LocalizedMethodFault
            newInfo = Object(name=info.name, type=faultType,
                             version=info.version, flags=info.flags)
            self._SerializeDataObject(newVal, newInfo, attr, currDefNS)
         else:
            self._SerializeDataObject(val, info, attr, currDefNS)
      elif isinstance(val, ManagedObject):
         if info.type is object:
            nsattr, qName = self._QName(ManagedObject, currDefNS)
            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
         if val._serverGuid is not None:
            attr += ' serverGuid="{0}"'.format(val._serverGuid)
         # val in vim type attr is not namespace qualified
         # TODO: Add a new "typens" attr?
         ns, name = GetQualifiedWsdlName(Type(val))
         attr += ' type="{0}"'.format(name)
         self.writer.write('<{0}{1}>{2}</{3}>'.format(info.name, attr,
                                              val._moId,
                                              info.name))
      elif isinstance(val, list):
         if info.type is object:
            itemType = val.Item
            if (itemType is ManagedMethod or itemType is PropertyPath
            or  itemType is type):
               tag = 'string'
               typ = GetVmodlType("string[]")
            elif issubclass(itemType, ManagedObject):
               tag = 'ManagedObjectReference'
               typ = ManagedObject.Array
            else:
               tag = GetWsdlName(itemType)
               typ = Type(val)
            nsattr, qName = self._QName(typ, currDefNS)

            # For WSDL, since we set tag of ManagedObjects to ManagedObjectReferences,
            # the name of its array should be ArrayOfManagedObjectReference
            if qName.endswith("ArrayOfManagedObject"):
               qName += "Reference"

            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
            self.writer.write('<{0}{1}>'.format(info.name, attr))

            itemInfo = Object(name=tag, type=itemType,
                              version=info.version, flags=info.flags)
            for it in val:
               self._Serialize(it, itemInfo, currDefNS)
            self.writer.write('</{0}>'.format(info.name))
         else:
            itemType = info.type.Item
            itemInfo = Object(name=info.name, type=itemType,
                              version=info.version, flags=info.flags)
            for it in val:
               self._Serialize(it, itemInfo, defNS)
      elif isinstance(val, type) or isinstance(val, type(Exception)):
         if info.type is object:
            attr += ' {0}type="{1}string"'.format(self.xsiPrefix, self.xsdPrefix)
         self.writer.write('<{0}{1}>{2}</{0}>'.format(
                           info.name, attr, GetWsdlName(val)))
      elif isinstance(val, ManagedMethod):
         if info.type is object:
            attr += ' {0}type="{1}string"'.format(self.xsiPrefix, self.xsdPrefix)
         self.writer.write('<{0}{1}>{2}</{0}>'.format(
                              info.name, attr, val.info.wsdlName))
      elif isinstance(val, datetime):
         if info.type is object:
            nsattr, qName = self._QName(Type(val), currDefNS)
            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
         result = Iso8601.ISO8601Format(val)
         self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
      elif isinstance(val, binary):
         if info.type is object:
            nsattr, qName = self._QName(Type(val), currDefNS)
            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
         result = base64.b64encode(val)
         if PY3:
            # In python3 the bytes result after the base64 encoding has a
            # leading 'b' which causes error when we use it to construct the
            # soap message. Workaround the issue by converting the result to
            # string. Since the result of base64 encoding contains only subset
            # of ASCII chars, converting to string will not change the value.
            result = str(result, XML_ENCODING)
         self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
      elif isinstance(val, bool):
         if info.type is object:
            nsattr, qName = self._QName(Type(val), currDefNS)
            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
         result = val and "true" or "false"
         self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
      elif isinstance(val, six.integer_types) or isinstance(val, float):
         if info.type is object:
            nsattr, qName = self._QName(Type(val), currDefNS)
            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
         result = six.text_type(val)
         self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
      elif isinstance(val, Enum):
         if info.type is object:
            nsattr, qName = self._QName(Type(val), currDefNS)
            attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)
         self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, val))
      else:
         if info.type is object:
            if isinstance(val, PropertyPath):
               attr += ' {0}type="{1}string"'.format(self.xsiPrefix, self.xsdPrefix)
            else:
               nsattr, qName = self._QName(Type(val), currDefNS)
               attr += '{0} {1}type="{2}"'.format(nsattr, self.xsiPrefix, qName)

         if isinstance(val, six.binary_type):
            # Use UTF-8 rather than self.encoding.  self.encoding is for
            # output of serializer, while 'val' is our input.  And regardless
            # of what our output is, our input should be always UTF-8.  Yes,
            # it means that if you emit output in other encoding than UTF-8,
            # you cannot serialize it again once more.  That's feature, not
            # a bug.
            val = val.decode(XML_ENCODING)
         result = XmlEscape(val)
         self.writer.write(u'<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
68579
def serialize(self, occur=None):
        
        fmt = self.ser_format.get(self.name, SchemaNode._default_format)
        return fmt(self, occur) % (escape(self.text) +
                                   self.serialize_children())
1280592
def serialize_table(ctx, document, table, root):
    

    # What we should check really is why do we pass None as root element
    # There is a good chance some content is missing after the import

    if root is None:
        return root

    if ctx.ilvl != None:
        root = close_list(ctx, root)
        ctx.ilvl, ctx.numid = None, None

    _table = etree.SubElement(root, 'table')
    _table.set('border', '1')
    _table.set('width', '100%')

    style = get_style(document, table)

    if style:
        _table.set('class', get_css_classes(document, style))

    for rows in table.rows:
        _tr = etree.SubElement(_table, 'tr')

        for cell in rows:
            _td = etree.SubElement(_tr, 'td')

            if cell.grid_span != 1:
                _td.set('colspan', str(cell.grid_span))

            if cell.row_span != 1:
                _td.set('rowspan', str(cell.row_span))

            for elem in cell.elements:
                if isinstance(elem, doc.Paragraph):
                    _ser = ctx.get_serializer(elem)
                    _td = _ser(ctx, document, elem, _td, embed=False)

            if ctx.ilvl != None:
#                root = close_list(ctx, root)
                _td = close_list(ctx, _td)

                ctx.ilvl, ctx.numid = None, None

            fire_hooks(ctx, document, table, _td, ctx.get_hook('td'))
        fire_hooks(ctx, document, table, _td, ctx.get_hook('tr'))

    fire_hooks(ctx, document, table, _table, ctx.get_hook('table'))

    return root
1284734
def serialize(self, content):
        
        return self.xmldoc_tpl % (
            'true' if self.response.status_code == HTTP_200_OK else 'false',
            str(self.resource.api or ''),
            int(mktime(datetime.now().timetuple())),
            super(XMLTemplateEmitter, self).serialize(content)
        )
476390
def _serialize(
            self,
            element,  # type: ET.Element
            value,  # type: Any
            state  # type: _ProcessorState
    ):
        # type: (...) -> None
        """"""
        xml_value = _hooks_apply_before_serialize(self._hooks, state, value)

        # A value is only considered missing, and hence eligible to be replaced by its
        # default only if it is None. Falsey values are not considered missing and are
        # not replaced by the default.
        if xml_value is None:
            if self._default is None:
                serialized_value = Text('')
            else:
                serialized_value = Text(self._default)
        else:
            serialized_value = Text(xml_value)

        if self._attribute:
            element.set(self._attribute, serialized_value)
        else:
            element.text = serialized_value
899690
public <T> void serialize(SerializerContext serializerContext, ElementDescriptor<T> descriptor, T rootObject) throws SerializerException, IOException
	{
		serializerContext.serializer.startDocument(null, null);
		useNamespace(serializerContext, descriptor.qualifiedName);
		bindNamespaces(serializerContext);
		mChildWriter.writeChild(descriptor, rootObject, serializerContext);
		serializerContext.serializer.endDocument();
	}
1230087
def tostring(self, root=None, doctype=None, pretty_print=True):
        """"""
        if root is None:
            root = self.root
        return etree.tounicode(
            root, doctype=doctype or self.info.doctype, pretty_print=pretty_print
        )
857887
def serialize_to_xml(root, block):
    
    root.tag = 'ubcpi'

    if block.rationale_size is not None:
        if block.rationale_size.get('min'):
            root.set('rationale_size_min', unicode(block.rationale_size.get('min')))
        if block.rationale_size.get('max'):
            root.set('rationale_size_max', unicode(block.rationale_size['max']))

    if block.algo:
        if block.algo.get('name'):
            root.set('algorithm', block.algo.get('name'))
        if block.algo.get('num_responses'):
            root.set('num_responses', unicode(block.algo.get('num_responses')))

    display_name = etree.SubElement(root, 'display_name')
    display_name.text = block.display_name

    question = etree.SubElement(root, 'question')
    question_text = etree.SubElement(question, 'text')
    question_text.text = block.question_text['text']
    serialize_image(block.question_text, question)

    options = etree.SubElement(root, 'options')
    serialize_options(options, block)

    seeds = etree.SubElement(root, 'seeds')
    serialize_seeds(seeds, block)
568149
def serialize(self):
        """"""
        res = '<?xml version="1.0" encoding="UTF-8"?>'
        for ns in self.namespaces:
            self.top_grammar.attr["xmlns:" + self.namespaces[ns]] = ns
        res += self.top_grammar.start_tag()
        for ch in self.top_grammar.children:
            res += ch.serialize()
        res += self.tree.serialize()
        for d in self.global_defs:
            res += self.global_defs[d].serialize()
        for i in self.identities:
            res += self.identities[i].serialize()
        return res + self.top_grammar.end_tag()