Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

forgiving-xml-parser

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forgiving-xml-parser

An forgiving XML/HTML parser and serializer for JavaScript.

  • 1.4.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-57.14%
Maintainers
1
Weekly downloads
 
Created
Source

forgiving-xml-parser

Build Status image image image

Enligsh | 简体中文

An XML/HTML parser and serializer for JavaScript. Playground

spec

Features

  • Transform XML/HTML to JSON(carry code locationInfo or parse steps)
  • Transform JSON back to XML
  • Works with node packages, in browser(like browser such as Miniprogram)
  • Various options are available to customize the transformation
    • custom parsing behavior(souch as allow node-name is empty)
    • supported events
    • custom node parser

Usage

  • 1.install
# using npm
npm i forgiving-xml-parser -S
# using yarn
yarn add forgiving-xml-parser
  • 2.include
// in node
const ForgivingXmlParser = require('forgiving-xml-parser');
const json = ForgivingXmlParser.parse('...');

// in webpack
import {parse, serialize, ...} from 'forgiving-xml-parser';
const json = parse('...');
<!-- in browser -->
<script src="xxx/forgiving-xml-parser.js"></script>
<script>
    // global variable
    const json = ForgivingXmlParser.parse("...");
</script>
  • 3.use
const { parse, serialize, parseResultToJSON, FxParser } = require("forgiving-xml-parser");

const xml = `<p>hi xml</p>`;
const json = parseResultToJSON(parse(xml), {
    allowAttrContentHasBr: true,
    allowNodeNameEmpty: true,
    allowNodeNotClose: true,
    allowStartTagBoundaryNearSpace: true,
    allowEndTagBoundaryNearSpace: true,
    allowTagNameHasSpace: true,
    allowNearAttrEqualSpace: true,
    ignoreTagNameCaseEqual: false,
    onEvent(type, context, data) {},
}); // { "nodes": [{ "type": "element", "name": "p", "children": [{ "type": "text", "content": "hi xml" }] }] }

serialize(json); // <p>hi xml</p>

const fxParser = new FxParser();
const json2 = parseResultToJSON(fxParser.parse(xml));
console.log(JSON.stringify(json2) === JSON.stringify(json)); // true
console.log(fxParser.serialize(json2) === serialize(json)); // true
Event trigger timing

Legend

Keywords

FAQs

Package last updated on 26 Sep 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc