https://github.com/shun-shobon/littlexml
1kB XML library for Node.js, Bun, Deno, Browser, Edge runtime.
https://github.com/shun-shobon/littlexml
cloudflare-workers deno javascript typescript xml
Last synced: 10 months ago
JSON representation
1kB XML library for Node.js, Bun, Deno, Browser, Edge runtime.
- Host: GitHub
- URL: https://github.com/shun-shobon/littlexml
- Owner: shun-shobon
- License: mit
- Created: 2023-03-11T06:43:31.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-08-17T21:23:18.000Z (10 months ago)
- Last Synced: 2025-08-18T01:49:38.727Z (10 months ago)
- Topics: cloudflare-workers, deno, javascript, typescript, xml
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@shun-shobon/littlexml
- Size: 1.59 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @shun-shobon/littlexml
1kB XML library for Node.js, Bun, Deno, Browser, Edge runtime.
[](https://www.npmjs.com/package/@shun-shobon/littlexml)
[](https://bundlephobia.com/package/@shun-shobon/littlexml)
[](https://github.com/shun-shobon/littlexml/actions/workflows/check.yml)
[](https://codecov.io/gh/shun-shobon/littlexml)
## About
This library is designed to run on small JavaScript runtimes such as Cloudflare
Workers. It also works on Node.js, Bun, Deno, and browsers.
## Features
- Render XML as a string, iterator, or stream.
- Render XML with indentation.
## Support platforms
- Node.js
- Deno
- Bun
- Browser
- Edge runtime like Cloudflare Workers, Vercel Edge Functions
## Installation
### Node.js / Bun
Install package from npm. You can also use yarn/pnpm instead of npm.
If you are using Bun, you can install with `bun add` command.
```sh
npm install @shun-shobon/littlexml
```
You can import from the package as `@shun-shobon/littlexml`.
```ts
import { element, renderToString } from "@shun-shobon/littlexml";
```
### Deno
You can directly import from `npm:@shun-shobon/littlexml`.
```ts
import { element, renderToString } from "npm:littlexml@0.6.2";
```
### Browser
You can directly import from `unpkg.com`.
```js
import {
element,
renderToString,
} from "https://unpkg.com/@shun-shobon/littlexml@0.6.2";
```
## Example
This example is rendering a sitemap.
```typescript
import { element, renderToString } from "@shun-shobon/littlexml";
const root = element("urlset")
.attr("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
.attr("xmlns:image", "http://www.google.com/schemas/sitemap-image/1.1")
.child(
element("url")
.child(element("loc").text("https://example.com/"))
.child(element("lastmod").text("2020-01-01"))
.child(element("changefreq").text("daily"))
.child(element("priority").text("0.8"))
.child(
element("image:image")
.child(element("image:loc").text("https://example.com/image.png"))
.child(element("image:caption").text("caption")),
),
);
const xml = renderToString(root, { version: "1.0", indent: 2 });
console.log(xml);
```
console output:
```xml
https://example.com/
2020-01-01
daily
0.8
https://example.com/image.png
caption
```