New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

xml-to-tree

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-to-tree

A utility for parsing XML strings into a tree structure - safe for fragments and multi-root.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

xml-to-tree

Canonical URL:
https://alexstevovich.com/a/xml-to-tree-nodejs

Software URL:
https://midnightcitylights.com/software/xml-to-tree-nodejs

xml-to-tree is a utility for parsing XML strings into a JSON tree representation. It is safe for XML fragments and multi-root documents, providing a clean structure for each node and its children.

Installation

npm install xml-to-tree

Example

import { parse } from 'xml-to-tree';

const xml = `
<book>
  <title>XML for Beginners</title>
  <author>John Doe</author>
  <year>2025</year>
</book>`;

const tree = parse(xml);

console.log(JSON.stringify(tree, null, 2));

Function

parse(xml, options = {})

  • xml: The XML string or fragment to parse.
  • options.tagKey: The key used for the tag name (default is 'tag').
  • options.childrenKey: The key used for child nodes (default is 'children').
  • options.textKey: The key used for text content (default is 'text').

Returns a JSON tree representation of the XML. It processes each element node, its attributes, and its child nodes recursively.

License

Licensed under the MIT License.

Keywords

xml

FAQs

Package last updated on 12 Nov 2025

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