Socket
Socket
Sign inDemoInstall

xml-formatter

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-formatter

Converts a XML string into a human readable format (pretty print) while respecting the xml:space attribute


Version published
Weekly downloads
422K
increased by0.03%
Maintainers
1
Weekly downloads
 
Created

What is xml-formatter?

The xml-formatter npm package is a utility for formatting XML strings. It helps in making XML data more readable by properly indenting the XML elements. This can be particularly useful for debugging, logging, or displaying XML data in a user-friendly format.

What are xml-formatter's main functionalities?

Basic Formatting

This feature allows you to format a simple XML string, making it more readable by adding appropriate indentation.

const xmlFormatter = require('xml-formatter');
const xml = '<root><child>value</child></root>';
const formattedXml = xmlFormatter(xml);
console.log(formattedXml);

Custom Indentation

This feature allows you to specify custom indentation for the formatted XML string. In this example, two spaces are used for indentation.

const xmlFormatter = require('xml-formatter');
const xml = '<root><child>value</child></root>';
const formattedXml = xmlFormatter(xml, { indentation: '  ' });
console.log(formattedXml);

Removing XML Declarations

This feature allows you to remove XML declarations from the formatted XML string. This can be useful if you want a cleaner output without the XML declaration.

const xmlFormatter = require('xml-formatter');
const xml = '<?xml version="1.0"?><root><child>value</child></root>';
const formattedXml = xmlFormatter(xml, { stripComments: true });
console.log(formattedXml);

Handling Large XML Strings

This feature demonstrates the ability of xml-formatter to handle and format large XML strings efficiently.

const xmlFormatter = require('xml-formatter');
const largeXml = '<root>' + '<child>value</child>'.repeat(1000) + '</root>';
const formattedXml = xmlFormatter(largeXml);
console.log(formattedXml);

Other packages similar to xml-formatter

Keywords

FAQs

Package last updated on 03 Feb 2022

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