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

xml-extractor

v1.0.3

Published

A lightweight library to extract and parse all XML blocks from a string

Readme

XML Extractor: Easily Retrieve XML from AI Conversations

AI language models mostly generate valid XML, but they often clutter it with casual text, markdown, or random tags. XML Extractor isolates clean XML from conversational noise, ready to use.

What Does XML Extractor Do?

AI-generated formatting can be unpredictable: sometimes neat inside code blocks, other times scattered in text. XML Extractor reliably handles:

  • XML within perfect or messy code blocks
  • XML snippets embedded in plain text
  • Converting extracted XML directly into JavaScript objects

No hassle, no complexity - just usable XML.

How to Use

Install via npm:

npm install xml-extractor

Example:

import { extractXMLObjects } from 'xml-extractor';

const aiResponse = `
Here's some XML treasure for you:
\`\`\`xml
<person><name>John</name></person>
\`\`\`
And bonus XML: <book><title>1984</title></book>
`;

try {
  const xmlObjects = await extractXMLObjects(aiResponse);
  console.log(xmlObjects);
} catch (error) {
  console.error('Error:', error.message);
}

Output:

[{ "person": { "name": "John" } }, { "book": { "title": "1984" } }]

Easy and straightforward. Don’t forget to validate the output with your favorite schema validator!

Why Mention AI and XML?

Modern LLMs often handle XML like champs - reading tags or outputting them with ease. But structured output or tool use? Not always built-in. With clever prompting, you can nudge an LLM to spit out XML, unlocking structured data or multi-step "tool" actions in one shot. I've used this trick in my own projects with solid results. Tools like Cline do it under the hood, enabling many different LLMs to work in codebases. XML’s a lightweight key to taming AI flexibility. I haven't found anyting that I liked - hence this library.

Why You’ll Like It

  • Handles AI Formatting Quirks: Reliably extracts XML regardless of formatting.
  • Lightweight and Simple: Single small file; no extra bloat.
  • Versatile: Designed with AI responses in mind, but works anywhere XML appears in strings.
  • Graceful Handling: Returns an empty array if no XML found; no errors.

FAQs

  • What if XML is inside incomplete code fences? XML Extractor still extracts it.

  • Can I customize extraction? Yes: just pass custom options to fast-xml-parser.

  • Performance? Built on fast-xml-parser: quick and reliable.

Feedback

Found a bug or have an idea? Visit the GitHub repository. Contributions welcome!

From the Author

Hi, I’m Seva. Built this out of frustration with extracting AI-generated XML from conversations. It solved my problem, and I hope it solves yours, too.

Happy extracting!