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 Util

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

Overview

Provides XML utility functions for attribute reading, numeric parsing, file path resolution, and error handling used by the MJCF and URDF parsers.

Description

xml_util.cc implements shared utility functions for MuJoCo's XML parsing subsystem. It includes ParseInfOrNan for handling special floating-point values (infinity and NaN) in XML attributes, ResolveFilePath for resolving file references relative to model directories with VFS support, and various mjXUtil class methods for reading typed attributes from XML elements. The file uses tinyxml2 for XML element traversal and attribute access, and handles robust numeric parsing with proper error detection.

Usage

Used as a shared utility library by both the native MJCF reader and the URDF parser for common XML parsing operations, attribute extraction, and error reporting.

Code Reference

Source Location

Key Functions

template <typename T>
static std::optional<T> ParseInfOrNan(const std::string& s);

FilePath ResolveFilePath(XMLElement* e, const FilePath& filename,
                         const FilePath& dir, const mjVFS* vfs);

// mjXUtil static methods:
// ReadAttrTxt, ReadAttrInt, ReadAttrFloat, ReadAttrDouble, etc.

Import

#include "xml/xml_util.h"
#include "user/user_resource.h"
#include "user/user_util.h"
#include "tinyxml2.h"

I/O Contract

Inputs

Name Type Required Description
e XMLElement* Yes XML element to read attributes from
filename const FilePath& Yes (for resolve) File path to resolve
dir const FilePath& Yes (for resolve) Base directory for path resolution
vfs const mjVFS* No Virtual file system for checking file existence

Outputs

Name Type Description
std::optional<T> std::optional<T> Parsed special float value (inf/nan), or nullopt if not a special value
FilePath FilePath Resolved file path combining directory and filename

Related Pages

Page Connections

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