or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

building.mdindex.mdparsing.mdvalidation.md
tile.json

index.mddocs/

Fast XML Parser

Fast XML Parser is a comprehensive XML processing library that validates XML data syntactically, parses XML to JavaScript objects, and builds XML from JavaScript objects without requiring C/C++ based dependencies. It offers high-performance XML processing with support for large files (tested up to 100MB), XML entities, HTML entities, DOCTYPE entities, unpaired tags, and stop nodes while maintaining the order of tags in JavaScript objects.

Package Information

  • Package Name: fast-xml-parser
  • Package Type: npm
  • Language: JavaScript/TypeScript
  • Installation: npm install fast-xml-parser

Core Imports

import { XMLParser, XMLValidator, XMLBuilder } from "fast-xml-parser";

For CommonJS:

const { XMLParser, XMLValidator, XMLBuilder } = require("fast-xml-parser");

Basic Usage

import { XMLParser, XMLValidator, XMLBuilder } from "fast-xml-parser";

// Validate XML
const isValid = XMLValidator.validate(xmlString);
if (isValid !== true) {
  console.log("Invalid XML:", isValid.err.msg);
}

// Parse XML to JavaScript object
const parser = new XMLParser();
const jsonObj = parser.parse(xmlString);
console.log(JSON.stringify(jsonObj, null, 2));

// Build XML from JavaScript object
const builder = new XMLBuilder();
const xmlOutput = builder.build(jsonObj);
console.log(xmlOutput);

Architecture

Fast XML Parser is built around three core components:

  • XMLValidator: Lightweight validation engine that checks XML syntax without full parsing
  • XMLParser: Main parsing engine that converts XML to JavaScript objects with extensive configuration options
  • XMLBuilder: Reverse engine that converts JavaScript objects back to XML strings with formatting controls
  • Configuration System: Comprehensive options system for customizing parsing and building behavior
  • Entity Processing: Built-in support for XML, HTML, and custom entities with extensible entity definitions

Capabilities

XML Validation

Fast validation of XML syntax and structure without the overhead of full parsing. Ideal for input validation and pre-processing checks.

XMLValidator.validate(xmlData: string, options?: validationOptions): true | ValidationError;

interface validationOptions {
  allowBooleanAttributes?: boolean;
  unpairedTags?: string[];
}

interface ValidationError {
  err: { 
    code: string;
    msg: string;
    line: number;
    col: number;
  };
}

XML Validation

XML Parsing

Converts XML strings to JavaScript objects with comprehensive configuration options for handling attributes, namespaces, entities, and data types.

class XMLParser {
  constructor(options?: X2jOptions);
  parse(xmlData: string | Buffer, validationOptions?: validationOptions | boolean): any;
  addEntity(entityIdentifier: string, entityValue: string): void;
  static getMetaDataSymbol(): Symbol;
}

interface X2jOptions {
  preserveOrder?: boolean;
  attributeNamePrefix?: string;
  attributesGroupName?: false | string;
  textNodeName?: string;
  ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean);
  // ... extensive additional options
}

XML Parsing

XML Building

Converts JavaScript objects to XML strings with formatting and structure control options. Supports both compact and pretty-printed output.

class XMLBuilder {
  constructor(options?: XmlBuilderOptions);
  build(jObj: any): string;
}

interface XmlBuilderOptions {
  attributeNamePrefix?: string;
  attributesGroupName?: false | string;
  textNodeName?: string;
  ignoreAttributes?: boolean | (string | RegExp)[] | ((attrName: string, jPath: string) => boolean);
  format?: boolean;
  indentBy?: string;
  // ... additional formatting and processing options
}

XML Building

CLI Interface

A built-in CLI is included but displays a deprecation warning and recommends using the standalone fxp-cli package instead.

# Binary command
fxparser [options] [input-file]

# Available options:
#   -h, --help          Show help information
#   --version          Show version number
#   -ns                Don't remove namespace prefixes
#   -a                 Ignore attributes
#   -c                 Don't parse tag and attribute values
#   -o <file>          Output to specified file
#   -v                 Validate XML while parsing
#   -V                 Validate XML only (no parsing)

Usage Examples:

# Basic parsing from file
fxparser input.xml

# Parse from stdin
cat input.xml | fxparser

# With validation
fxparser -v input.xml

# Validate only
fxparser -V input.xml

# Output to file
fxparser -o output.json input.xml

# Parse without removing namespaces
fxparser -ns input.xml

# Ignore attributes
fxparser -a input.xml

# Don't convert values (keep as strings)
fxparser -c input.xml

Deprecation Notice: This CLI shows a deprecation warning. For new projects, install the dedicated CLI package:

npm install -g fxp-cli