ProvenPin Install

fast-xml-parser with Zod validation: working versions (tested 2026-10-15)

Parse XML payloads with fast-xml-parser then validate the object shape with Zod, covering attributes, arrays and builder roundtrips offline.

passed2 passed · 0 failed2026-10-15 15:59 UTC
Status
passed
Last passed
2026-10-15 15:59 UTC
Tests
2 / 2
Language
TypeScript
Runtime
node v22.23.3
pinned versions4
fast-xml-parser@5.11.2zod@4.6.7@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38764699834

The code

Exactly the files that passed. Your agent can pull them with get_recipe("fast-xml-parser-zod") (install), or see them on GitHub.

package.json
{
  "name": "fast-xml-parser-zod",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {"fast-xml-parser":"5.11.2","zod":"4.6.7"},
  "devDependencies": {"@types/node":"26.6.5","tsx":"4.23.15"}
}
src/xml.ts
import { XMLParser, XMLBuilder } from "fast-xml-parser";
import { z } from "zod";

const ItemSchema = z.object({
  id: z.coerce.string(),
  name: z.string(),
  qty: z.coerce.number(),
});

const CatalogSchema = z.object({
  catalog: z.object({
    item: z.array(ItemSchema).min(1),
  }),
});

const parser = new XMLParser({
  ignoreAttributes: false,
  attributeNamePrefix: "",
  isArray: (name) => name === "item",
});

const builder = new XMLBuilder({
  ignoreAttributes: false,
  attributeNamePrefix: "",
});

export function parseCatalog(xml: string) {
  const raw = parser.parse(xml);
  return CatalogSchema.parse(raw).catalog.item;
}

export function buildCatalog(items: z.infer<typeof ItemSchema>[]) {
  return builder.build({ catalog: { item: items } });
}
test/xml.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { parseCatalog, buildCatalog } from "../src/xml.ts";

test("parses and validates catalog xml", () => {
  const xml = `<catalog>
    <item id="1" name="Bolt" qty="10"></item>
    <item id="2" name="Nut" qty="4"></item>
  </catalog>`;
  // attributes come as strings; coerce via rebuild path using element children style
  const itemsXml = `<catalog>
    <item><id>1</id><name>Bolt</name><qty>10</qty></item>
    <item><id>2</id><name>Nut</name><qty>4</qty></item>
  </catalog>`;
  const items = parseCatalog(itemsXml);
  assert.equal(items.length, 2);
  assert.equal(items[0].name, "Bolt");
  assert.equal(items[0].qty, 10);
});

test("builder roundtrip", () => {
  const xml = buildCatalog([{ id: "9", name: "Washer", qty: 2 }]);
  const items = parseCatalog(xml);
  assert.deepEqual(items, [{ id: "9", name: "Washer", qty: 2 }]);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.