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

node-expat

Package Overview
Dependencies
Maintainers
5
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-expat

NodeJS binding for fast XML parsing.

  • 2.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
125K
decreased by-1.31%
Maintainers
5
Weekly downloads
 
Created

What is node-expat?

The node-expat package is a fast XML parser for Node.js, which is a binding for the Expat XML parser library. It is used to parse XML documents efficiently and can handle large XML files with ease. It provides a streaming interface for XML parsing, making it suitable for applications that need to process XML data in real-time or in chunks.

What are node-expat's main functionalities?

Basic XML Parsing

This feature allows you to parse XML documents and handle different events such as start and end of elements, and text nodes. The code sample demonstrates how to set up a basic XML parser and handle these events.

const expat = require('node-expat');
const parser = new expat.Parser('UTF-8');

parser.on('startElement', (name, attrs) => {
  console.log(`Start element: ${name}`);
  console.log(attrs);
});

parser.on('endElement', (name) => {
  console.log(`End element: ${name}`);
});

parser.on('text', (text) => {
  console.log(`Text: ${text}`);
});

const xml = '<root><child id="1">Hello</child></root>';
parser.write(xml);

Streaming XML Parsing

This feature allows you to parse large XML files by streaming the data. The code sample demonstrates how to set up a streaming XML parser that reads from a file stream, making it suitable for processing large XML files without loading the entire file into memory.

const fs = require('fs');
const expat = require('node-expat');
const parser = new expat.Parser('UTF-8');

parser.on('startElement', (name, attrs) => {
  console.log(`Start element: ${name}`);
  console.log(attrs);
});

parser.on('endElement', (name) => {
  console.log(`End element: ${name}`);
});

parser.on('text', (text) => {
  console.log(`Text: ${text}`);
});

const stream = fs.createReadStream('path/to/large.xml');
stream.pipe(parser);

Other packages similar to node-expat

Keywords

FAQs

Package last updated on 08 Mar 2024

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