MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / to_xml_string

Method to_xml_string

dm_control/mjcf/element.py:817–862  ·  view source on GitHub ↗

Generates an XML string corresponding to this MJCF element. Args: prefix_root: (optional) A `NameScope` object to be treated as root for the purpose of calculating the prefix. If `None` then no prefix is included. self_only: (optional) A boolean, whether to generate

(self, prefix_root=None,
                    self_only=False, pretty_print=True, debug_context=None,
                    *,
                    precision=constants.XML_DEFAULT_PRECISION,
                    zero_threshold=0, filename_with_hash=True)

Source from the content-addressed store, hash-verified

815 child_xml.insert(0, copy.deepcopy(debug_comment))
816
817 def to_xml_string(self, prefix_root=None,
818 self_only=False, pretty_print=True, debug_context=None,
819 *,
820 precision=constants.XML_DEFAULT_PRECISION,
821 zero_threshold=0, filename_with_hash=True):
822 """Generates an XML string corresponding to this MJCF element.
823
824 Args:
825 prefix_root: (optional) A `NameScope` object to be treated as root
826 for the purpose of calculating the prefix.
827 If `None` then no prefix is included.
828 self_only: (optional) A boolean, whether to generate an XML corresponding
829 only to this element without any children.
830 pretty_print: (optional) A boolean, whether to the XML string should be
831 properly indented.
832 debug_context: (optional) A `debugging.DebugContext` object to which
833 the debugging information associated with the generated XML is written.
834 This is intended for internal use within PyMJCF; users should never need
835 manually pass this argument.
836 precision: (optional) Number of digits to output for floating point
837 quantities.
838 zero_threshold: (optional) When outputting XML, floating point quantities
839 whose absolute value falls below this threshold will be treated as zero.
840 filename_with_hash: (optional) A boolean, whether to append a hash string
841 to the name of a file when it is registered in MuJoCo's VFS.
842
843 Returns:
844 A string.
845 """
846 xml_element = self.to_xml(prefix_root, debug_context,
847 precision=precision,
848 zero_threshold=zero_threshold,
849 filename_with_hash=filename_with_hash)
850 if self_only and len(xml_element) > 0: # pylint: disable=g-explicit-length-test
851 etree.strip_elements(xml_element, '*')
852 xml_element.text = '...'
853 if (self_only and self._spec.identifier and
854 not self._attributes[self._spec.identifier].to_xml_string(
855 prefix_root, precision=precision, zero_threshold=zero_threshold)):
856 del xml_element.attrib[self._spec.identifier]
857 xml_string = util.to_native_string(
858 etree.tostring(xml_element, pretty_print=pretty_print))
859 if pretty_print and debug_context:
860 return debug_context.commit_xml_string(xml_string)
861 else:
862 return xml_string
863
864 def __str__(self):
865 return self.to_xml_string(self_only=True, pretty_print=False)

Callers 6

__str__Method · 0.95
prefixed_identifierMethod · 0.45
_attributes_to_xmlMethod · 0.45
get_assetsMethod · 0.45
__str__Method · 0.45

Calls 2

to_xmlMethod · 0.95
commit_xml_stringMethod · 0.80

Tested by

no test coverage detected