Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco XML Native Writer

From Leeroopedia
Knowledge Sources
Domains Physics Simulation, XML Serialization, MJCF Format
Last Updated 2026-02-15 04:00 GMT

Overview

Implements the native MJCF XML writer that serializes MuJoCo model specifications back to XML format.

Description

xml_native_writer.cc converts MuJoCo model specification data structures back into MJCF XML documents using tinyxml2. It provides a custom mj_XMLPrinter class that overrides the default indentation to use 2 spaces instead of 4, and a WriteDoc function that serializes the document and inserts blank lines between top-level MJCF sections (actuator, asset, compiler, contact, custom, default, equality, extension, keyframe, option, sensor, size, statistic, tendon, visual, worldbody). The writer handles all MJCF elements and their attributes, including plugin configurations.

Usage

Called when saving models via mj_saveXML, mj_saveXMLString, or mj_saveLastXML to produce well-formatted MJCF XML output.

Code Reference

Source Location

Key Functions

class mj_XMLPrinter : public tinyxml2::XMLPrinter {
 public:
  void PrintSpace(int depth);  // 2-space indentation
};

static string WriteDoc(XMLDocument& doc, char* error, size_t error_sz);

Import

#include "xml/xml_native_writer.h"
#include "user/user_model.h"
#include "user/user_objects.h"
#include "xml/xml_util.h"
#include "tinyxml2.h"

I/O Contract

Inputs

Name Type Required Description
doc XMLDocument& Yes TinyXML2 document to serialize
s const mjSpec* Yes Model specification to write
error char* No Buffer for error messages
error_sz size_t No Size of error buffer

Outputs

Name Type Description
string std::string Serialized MJCF XML content with 2-space indentation
int int Return code (0 on success, -1 on failure)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment