@tabnas/xml
v0.2.0
Published
This plugin allows the [Jsonic](https://github.com/tabnas/jsonic) JSON parser to support xml syntax.
Downloads
82
Maintainers
Readme
@tabnas/xml
A Jsonic grammar plugin that parses XML text into a tree of elements, with support for attributes, mixed content, namespaces, entities, CDATA sections, comments, processing instructions, and DOCTYPE declarations.
This is the TypeScript / JavaScript package. A Go port lives in
../go (see its README).
Install
npm install @tabnas/parser @tabnas/jsonic @tabnas/xml@tabnas/parser (the engine) and @tabnas/jsonic (the base grammar) are
peer dependencies.
Example
const { Tabnas } = require('@tabnas/parser')
const { jsonic } = require('@tabnas/jsonic')
const { Xml } = require('@tabnas/xml')
const xml = new Tabnas().use(jsonic).use(Xml)
xml.parse('<a>Tom & Jerry</a>').children // => ['Tom & Jerry']The result is an XmlElement tree: each element has name, localName,
attributes, children, and — where they apply — prefix,
namespace, space, and lang.
Documentation
Organised by the Diátaxis framework:
- Tutorial — a guided first parse.
- How-to guide — task recipes (options, errors, embed mode).
- Reference — the public API, every option, and the accepted XML syntax.
- Concepts — how the parser works on the engine, and why.
Grammar diagram
The installed grammar as a railroad/syntax diagram, generated from the
live grammar with
@tabnas/railroad:
A vertical ASCII version is in doc/grammar.txt. The
grammar source lives in the repository's top-level xml-grammar.jsonic
and is embedded into src/xml.ts by embed-grammar.js
(run via npm run build or npm run embed).
License
Copyright (c) Richard Rodger and other contributors, MIT License.
