npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hatimsue/xml-core

v1.1.2

Published

A core library for creating XML elements and building XML documents.

Readme

npm Status

xml-core

This is a lightweight JavaScript library designed for building XML documents. It allows you to create XML element representations as instances of classes, where each object can have attributes and child elements added dynamically. The resulting XML can then be output as a string, ready to be displayed on-screen or saved to a file.

This package is intended as an intermediate step for projects that require XML generation, providing a foundation that can be further abstracted for ease of use in more specialized libraries.

Installation

npm install @hatimsue/xml-core

Example

import { XMLCData, XMLComment, XMLElement } from '@hatimsue/xml-core'

const authors = ['J.K. Rowling', 'J.R.R. Tolkien', 'George R.R. Martin']

// Create the root element <Library>
const library = new XMLElement( {
    name: 'Library',
    attributes: { location: 'UK' }
} )

// Add a comment
const comment = new XMLComment( 'This is a library XML document' )
library.addChild( comment )

// Create <Books> with the "genre" attribute
const books = new XMLElement( {
    name: 'Books',
    attributes: { genre: 'fantasy' }
} )

// Add <Book> elements for each author
authors.forEach( author => {
    const book = new XMLElement( {
        name: 'Book',
        attributes: { lang: 'en' }
    } )

    // Add Author and Name as child elements
    book.addChild( new XMLElement( { name: 'Author', children: [author] } ) )
    book.addChild( new XMLElement( { name: 'Name', children: [`A book by ${author}`] } ) )

    books.addChild( book )
} )

// Find an element by tag name and print its text content
console.log( '--- Example: innerText of first <Book> element ---' )
const firstBook = books.getElementByTagName( 'Book' )
console.log( firstBook.innerText )
console.log( '-----------------------------------------------\n' )

// Create an ExtraInfo element with CDATA using the XMLCData class
const extraInfo = new XMLElement( { name: 'ExtraInfo' } )
const cdata = new XMLCData( 'Some unparsed <CDATA> content goes here & should not be escaped.' )
extraInfo.addChild( cdata )

// Add the ExtraInfo element to the XML
library.addChild( books )
library.addChild( extraInfo )

// Convert the XML to a pretty-printed format
console.log( '--- Example: Pretty-printed XML ---' )
console.log( library.toPrettyXML() )
console.log( '-----------------------------------' )

Reference

The classes are designed to be simple and easy to read, so it's recommended to refer to them directly in the src/ folder or consult the auto-generated documentation in API.md. Additionally, you can generate the documentation by running npm run doc, which will create the documentation in the docs folder. However, the following table provides some basic usage examples, though it is not exhaustive.

| Concept | Description | Syntax / Example | Expected XML Output | |--------------------------------|---------------------------------------------------------------------------------|---------------------------------------------------|--------------------------------------------| | Create a tag | Use the XMLElement class constructor to create a tag. | new XMLElement('Book') | <Book/> | | Add content | Pass strings or nested elements to the tag using methods like addChild. | book.addChild('Title') | <Book>Title</Book> | | Add attribute | Use the setAttribute method to add attributes to the tag. | book.setAttribute('lang', 'en') | <Book lang="en"/> | | Chain attributes | Chain multiple calls to setAttribute to add more attributes. | book.setAttribute('lang', 'en').setAttribute('year', '2001') | <Book lang="en" year="2001"/> | | Add comment | Create a new XMLComment and add it using addChild. | book.addChild(new XMLComment('Note here')) | <!-- Note here --> | | Add CDATA section | Use the addChild method to insert a XMLCData section. | book.addChild(new XMLCData('<tag>')) | <![CDATA[<tag>]]> | | Single line output | Use the toXML() method to generate a compact XML string. | book.toXML() | <Book lang="en"><Author>J.K. Rowling</Author></Book> | | Multiline XML output | Use the toPrettyXML() method to generate an indented XML string. | book.toPrettyXML() | Formatted multi-line XML | | Root element | Start your XML tree with a root tag using the class constructor. | const library = new XMLElement('Library') | <Library>...</Library> |