Implementation:Google deepmind Mujoco XML Native Reader
| Knowledge Sources | |
|---|---|
| Domains | Physics Simulation, XML Parsing, MJCF Format |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Implements the native MJCF XML reader that parses MuJoCo's proprietary XML format into model specification objects.
Description
xml_native_reader.cc is a large (4605 lines) module that reads MJCF XML documents and populates the MuJoCo specification data structures. It parses all MJCF sections including compiler settings, options, assets, worldbody, actuators, sensors, contacts, equality constraints, tendons, and custom elements. The file handles plugin configuration via ReadPluginConfigs, processes composite and flexcomp elements, and validates attribute values against expected types and ranges using mjXUtil helper functions.
Usage
Called by the XML parser (xml.cc) when a native MJCF document is detected, reading each XML element and translating it into the corresponding MuJoCo specification objects.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: src/xml/xml_native_reader.cc
- Lines: 1-4605
Key Functions
void ReadPluginConfigs(tinyxml2::XMLElement* elem, mjsPlugin* p);
// mjXReader class methods for parsing each MJCF section:
// ReadCompiler, ReadOption, ReadAsset, ReadWorldbody,
// ReadActuator, ReadSensor, ReadContact, etc.
Import
#include "xml/xml_native_reader.h"
#include "user/user_api.h"
#include "user/user_composite.h"
#include "user/user_flexcomp.h"
#include "xml/xml_util.h"
#include "tinyxml2.h"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| elem | tinyxml2::XMLElement* | Yes | Root or section XML element to parse |
| spec | mjSpec* | Yes | Model specification to populate |
| p | mjsPlugin* | No | Plugin configuration target |
Outputs
| Name | Type | Description |
|---|---|---|
| mjSpec* | mjSpec* | Populated model specification with all parsed MJCF data |
| throws mjXError | exception | Thrown on parse errors with element context and message |