Implementation:Google deepmind Mujoco XML Util
| 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
- Repository: Google_deepmind_Mujoco
- File: src/xml/xml_util.cc
- Lines: 1-1160
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 |