Implementation:Google deepmind Mujoco XML Parser
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, XML Parsing |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements the top-level XML parsing and saving interface for MuJoCo models, dispatching between MJCF and URDF formats.
Description
xml.cc serves as the main entry point for XML-based model loading and saving in MuJoCo. It uses tinyxml2 for XML document parsing, dispatches to mjXReader (MJCF native reader) or mjXURDF (URDF reader) based on document structure, and handles locale management to ensure consistent numeric formatting across different system locales. The file implements LocaleOverride classes for Windows, macOS, and Linux that temporarily switch to the "C" locale during XML operations to prevent comma-vs-period decimal separator issues.
Usage
Called when loading models via mj_loadXML, mj_parseXML, mj_saveXML, or any other XML-based model I/O operations.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/xml/xml.cc
- Lines: 1-395
Key Functions
// Top-level parsing using tinyxml2
// Locale-safe XML operations via LocaleOverride
// Dispatches to xml_native_reader.h (MJCF) or xml_urdf.h (URDF)
class LocaleOverride {
public:
LocaleOverride(); // switches to "C" locale
~LocaleOverride(); // restores original locale
};
Import
#include "xml/xml.h"
#include "xml/xml_native_reader.h"
#include "xml/xml_native_writer.h"
#include "xml/xml_urdf.h"
#include "tinyxml2.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| filename | const char* | Yes | Path to XML file (MJCF or URDF format) |
| vfs | const mjVFS* | No | Virtual file system for resource lookups |
| error | char* | No | Buffer for error messages |
| error_sz | int | No | Size of error buffer |
Outputs
| Name | Type | Description |
|---|---|---|
| mjSpec* | mjSpec* | Parsed model specification from XML input |
| mjModel* | mjModel* | Compiled model (from mj_loadXML) |
| int | int | Return code for save operations (0 on success) |