GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - violentmonkey/xml-parser: Lightweight XML to JSON parser with zero dependencies

BranchesTags
Open more actions menu

Latest commit

 

History

12 Commits
12 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.husky
.husky
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.oxfmtrc.json
.oxfmtrc.json
 
 
.oxlintrc.json
.oxlintrc.json
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
index.ts
index.ts
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 
tsconfig.json
tsconfig.json
 
 
vite.config.ts
vite.config.ts
 
 

Repository files navigation

@violentmonkey/xml-parser

Open on npmx.dev Open on npmx.dev Open on npmx.dev

Lightweight XML to JSON parser with zero dependencies. Works in browser, Node.js, and Deno.

Designed for parsing XML APIs (WebDAV PROPFIND, S3 ListBucket, etc.) in environments where DOMParser is unavailable — such as service workers.

Usage

import { parseXml } from "@violentmonkey/xml-parser";

const { node, warnings } = parseXml(`<?xml version="1.0"?>
<D:multistatus xmlns:D="DAV:">
  <D:response>
    <D:href>/file.txt</D:href>
    <D:propstat>
      <D:prop>
        <D:displayname>file.txt</D:displayname>
        <D:getcontentlength>1234</D:getcontentlength>
      </D:prop>
      <D:status>HTTP/1.1 200 OK</D:status>
    </D:propstat>
  </D:response>
</D:multistatus>`);

// node.multistatus.response.href         → "/file.txt"
// node.multistatus.response.propstat.prop.displayname → "file.txt"
// node.multistatus.response.propstat.prop.getcontentlength → 1234 (number)

API

parseXml(input, options?)

Parameters:

  • input (string) — XML text to parse.
  • options (optional):
    • ignoreAttributes (boolean) — Skip all attributes. Default false.
    • removeNSPrefix (boolean) — Strip namespace prefixes from element names. Default true.

Returns: { node: Record<string, XmlValue>, warnings: Warning[] }

XmlValue

type XmlValue = string | number | { [key: string]: XmlValue } | XmlValue[];

Features

Feature Description
Namespace handling Strips D: → D:response becomes response by default. Opt out with removeNSPrefix: false.
Attributes Prefixed with @, e.g. <item id="42"> → { "@id": "42" }. xmlns* attributes are skipped.
Text vs object Text-only elements return string/number; elements with children return object.
Arrays Repeated sibling elements are automatically wrapped in an array.
Numbers Numeric strings like "1234" are parsed as numbers.
CDATA CDATA sections are treated as text content.
Warnings Non-fatal issues (e.g. duplicate attributes) are returned in warnings array.
Zero dependencies ~250 lines of pure TypeScript.

License

MIT

About

Lightweight XML to JSON parser with zero dependencies

Resources

Readme
MIT license
Activity
Custom properties

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.