MCPcopy Create free account
hub / github.com/sissaschool/xmlschema / encode

Method encode

xmlschema/dataobjects.py:308–333  ·  view source on GitHub ↗

Encodes the data object to XML. :param validation: the validation mode. Can be 'lax', 'strict' or 'skip. :param kwargs: optional keyword arguments for the method :func:`iter_encode` \ of :class:`XsdElement`. :return: An ElementTree's Element. If *validation*

(self, validation: str = 'strict', **kwargs: Any)

Source from the content-addressed store, hash-verified

306 del result
307
308 def encode(self, validation: str = 'strict', **kwargs: Any) -> EncodeType[ElementType]:
309 """
310 Encodes the data object to XML.
311
312 :param validation: the validation mode. Can be 'lax', 'strict' or 'skip.
313 :param kwargs: optional keyword arguments for the method :func:`iter_encode` \
314 of :class:`XsdElement`.
315 :return: An ElementTree's Element. If *validation* argument is 'lax' a \
316 2-items tuple is returned, where the first item is the encoded object and \
317 the second item is a list with validation errors.
318 :raises: :exc:`XMLSchemaValidationError` if the object is invalid \
319 and ``validation='strict'``.
320 """
321 kwargs['namespaces'] = self.get_namespaces(kwargs.get('namespaces'), False)
322 if 'converter' not in kwargs:
323 kwargs['converter'] = DataElementConverter
324
325 encoder: Union['XsdElement', BaseXsdType]
326 if self._encoder is not None:
327 encoder = self._encoder
328 elif validation == 'skip':
329 encoder = validators.XMLSchema.builtin_types()['anyType']
330 else:
331 raise XMLSchemaValueError("%r has no schema bindings" % self)
332
333 return encoder.encode(self, validation=validation, **kwargs)
334
335 to_etree = encode
336

Calls 4

get_namespacesMethod · 0.95
XMLSchemaValueErrorClass · 0.90
builtin_typesMethod · 0.80
getMethod · 0.45