Skip to main content

Function: parseMaterialX()

parseMaterialX(xml, limits?): MaterialXDocument

Parses MaterialX XML text into a MaterialXDocument.

Preserves ordered elements, explicit attributes, text and comments semantically. Source whitespace, quote style and XML declarations are not preserved byte-for-byte. Throws with line and column on malformed XML or a missing <materialx> root.

Example:

const document = parseMaterialX(await readFile('material.mtlx', 'utf8'));
console.log(document.attributes.version, document.nodeGraphs.length);

Reference:

Parameters​

xml​

string

limits?​

Partial<MaterialXReadLimits>

Returns​

MaterialXDocument