Security News
JavaScript Leaders Demand Oracle Release the JavaScript Trademark
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
@lezer/xml is a parser for XML syntax built on the Lezer parser system. It provides tools to parse XML documents, create syntax trees, and perform syntax highlighting. This package is useful for applications that need to process or analyze XML data.
Parsing XML
This feature allows you to parse an XML string and generate a syntax tree. The code sample demonstrates how to parse a simple XML string and print the resulting syntax tree.
const {parser} = require('@lezer/xml');
const input = '<root><child>Content</child></root>';
const tree = parser.parse(input);
console.log(tree.toString());
Syntax Highlighting
This feature allows you to perform syntax highlighting on an XML string. The code sample demonstrates how to parse an XML string and apply syntax highlighting using CodeMirror's highlighting utilities.
const {parser} = require('@lezer/xml');
const {highlightTree} = require('@codemirror/highlight');
const {defaultHighlighter} = require('@codemirror/highlight');
const input = '<root><child>Content</child></root>';
const tree = parser.parse(input);
let highlighted = '';
highlightTree(tree, defaultHighlighter, (from, to, classes) => {
highlighted += input.slice(from, to);
highlighted += ` [${classes}]`;
});
console.log(highlighted);
xml2js is a simple XML to JavaScript object converter. It is useful for converting XML data into a more manageable JavaScript object format. Unlike @lezer/xml, which focuses on parsing and syntax trees, xml2js is more about data transformation.
fast-xml-parser is a fast and lightweight XML parser that can convert XML to JSON and vice versa. It is designed for performance and ease of use. Compared to @lezer/xml, fast-xml-parser is more focused on data conversion rather than syntax analysis.
sax is a streaming XML parser for JavaScript. It provides an event-based API for parsing XML documents. While @lezer/xml is more about building syntax trees, sax is useful for applications that need to process XML data in a streaming fashion.
This is an XML grammar for the lezer parser system.
The code is licensed under an MIT license.
1.0.5 (2024-03-04)
Fix a mistake that broke highlighting for mismatched tag names.
FAQs
lezer-based XML grammar
The npm package @lezer/xml receives a total of 182,318 weekly downloads. As such, @lezer/xml popularity was classified as popular.
We found that @lezer/xml demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In an open letter, JavaScript community leaders urge Oracle to give up the JavaScript trademark, arguing that it has been effectively abandoned through nonuse.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.