Essentials for schema-driven, type-safe XML processing
Check out /example for a working example.
# install the generator and dependencies
yarn add xsd-tools xmldom
yarn add -D @xsd-tools/typescript
# generate types and parser based on xml schema
yarn run xsd-ts example/greeting.xsd example/greeting.ts
// feed xml dom into parser to get the typed valid object structure
import { readFileSync } from 'fs';
import { DOMParser } from '@xmldom/xmldom';
import parse from './greeting.ts';
const xml = readFileSync('example/greeting.xml', 'utf8');
const dom = new DOMParser().parseFromString(xml, 'text/xml');
const { greeting } = parse(dom);
console.log(`${greeting['@from']}: ${greeting['#']}`);
MIT