Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 952 Bytes

README.md

File metadata and controls

39 lines (26 loc) · 952 Bytes

xsd tools logo

xsd-tools

Essentials for schema-driven, type-safe XML processing

Example

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['#']}`);

License

MIT