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 mj saveLastXML

From Leeroopedia
Knowledge Sources
Domains Model_IO, Serialization
Last Updated 2026-02-15 06:00 GMT

Overview

Concrete tool for exporting the last loaded model as MJCF XML provided by the MuJoCo C API.

Description

The mj_saveLastXML function writes the internally stored XML specification from the last mj_loadXML call to a file or stdout. The output is a canonicalized MJCF XML with all defaults expanded and includes inlined.

Usage

Call after mj_loadXML to export the resolved model. If filename is NULL or empty, output goes to stdout.

Code Reference

Source Location

  • Repository: mujoco
  • File: src/xml/xml_api.cc
  • Lines: 76-96

Signature

int mj_saveLastXML(const char* filename, const mjModel* m,
                   char* error, int error_sz);

Import

#include <mujoco/mujoco.h>

I/O Contract

Inputs

Name Type Required Description
filename const char* No Output file path (NULL/empty for stdout)
m const mjModel* Yes Compiled model (for reference)
error char* No Error buffer
error_sz int No Error buffer size

Outputs

Name Type Description
return int 1 on success, 0 on failure
file MJCF XML Written to filename or stdout

Usage Examples

#include <mujoco/mujoco.h>

// Load and re-export as canonical XML
char error[1000];
mjModel* m = mj_loadXML("input.urdf", NULL, error, 1000);
if (m) {
    mj_saveLastXML("output.xml", m, error, 1000);
    mj_deleteModel(m);
}

Related Pages

Implements Principle

Page Connections

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