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 API Header

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

Overview

Declares the public C API for loading, saving, and parsing MuJoCo models from XML files and binary MJB files.

Description

xml_api.h is a compact header (59 lines) that declares the core XML I/O functions: mj_loadXML (parse and compile XML to model), mj_saveLastXML (save current model as MJCF), mj_freeLastXML (free cached XML model), mj_printSchema (output MJCF schema as text or HTML), mj_loadModel (load binary MJB), mj_parseXML/mj_parseXMLString (parse to spec without compiling), and mj_saveXML/mj_saveXMLString (save spec to XML). All functions use MJAPI export macros and extern "C" for C compatibility.

Usage

Included by any code that needs to load, save, or parse MuJoCo models via the public XML or binary file API.

Code Reference

Source Location

Key Functions

MJAPI mjModel* mj_loadXML(const char* filename, const mjVFS* vfs, char* error, int error_sz);
MJAPI int mj_saveLastXML(const char* filename, const mjModel* m, char* error, int error_sz);
MJAPI void mj_freeLastXML(void);
MJAPI int mj_printSchema(const char* filename, char* buffer, int buffer_sz,
                         int flg_html, int flg_pad);
MJAPI mjModel* mj_loadModel(const char* filename, const mjVFS* vfs);
MJAPI mjSpec* mj_parseXML(const char* filename, const mjVFS* vfs, char* error, int error_sz);
MJAPI mjSpec* mj_parseXMLString(const char* xml, const mjVFS* vfs, char* error, int error_sz);
MJAPI int mj_saveXML(const mjSpec* s, const char* filename, char* error, int error_sz);
MJAPI int mj_saveXMLString(const mjSpec* s, char* xml, int xml_sz, char* error, int error_sz);

Import

#include "xml/xml_api.h"

I/O Contract

Inputs

Name Type Required Description
filename const char* Yes Path to XML or MJB file
vfs const mjVFS* No Virtual file system for file lookups
xml const char* Yes (for parseXMLString) Raw XML string to parse
error char* No Buffer for error messages
error_sz int No Size of error buffer

Outputs

Name Type Description
mjModel* mjModel* Compiled model from XML or MJB file
mjSpec* mjSpec* Parsed model specification
int int Return code (0 on success, -1 on failure for save operations)

Related Pages

Page Connections

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