
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
typed-xml-builder
Advanced tools
Type-safe xml paser and builder based in xsd for Typescript environments
Type-safe XML parser and builder based in XSD file for Typescript environments
npm i typexml
or yard add typexml
In your project, after installing typexml
, run the following to generate types
for your XSD:
npx typexml generate ${path-to-xsd-file.xsd}
This should generate interfaces.ts
.
interfaces.ts
holds the collection of types extracted from the provided XSD
schema. It can be imported anywhere you want to generate a compliant XML.
Let's say you want to generate the element "foo" defined in your XSD file
import { createBuilder } from 'typemxml';
import { Schema } from '/path/to/interfaces.ts';
const schema: Schema = {
foo: {
// fill in foo props with type safety...
bar: 'bar'
...props,
},
};
const build = createBuilder('path-to-xsd-file.xsd');
const xml: string = build(schema, 'foo');
writeFileSync('foo.xml', xml);
You can validate the XML with the help of
xsd-validator
package
(npm i xsd-validator
) (or any other library of your choice...)
import { readFileSync } from 'fs';
import validateSchema, { ValidationError } from 'xsd-schema-validator';
const xsd = readFileSync('path-to-xsd-file.xsd').toString();
const errors: true | ValidationError[] = validateSchema(xml, xsd);
if (errors instanceof Array) {
errors.forEach(e => console.error(e));
throw new Error('Invalid XML');
}
It also comes with a parser in case you need
import { readFileSync } from 'fs';
import { createParser } from 'typemxml';
import { Foo } from '/path/to/interfaces.ts';
const xml = readFileSync('path-to-xml-file.xml').toString();
const parse = createParser<Foo>('path-to-xsd-file.xsd');
// whatever element was parsed is guaranteed to comply with both XSD/interface
const foo: Foo = parse(xml);
console.log(foo.bar.length);
import { readFileSync } from 'fs';
import { createParser } from 'typemxml';
const xml = readFileSync('path-to-xml-file.xml').toString();
const parse = createParser();
// parse as any other regular xml parser returning a loosely typed Record<string, any>
const foo: Record<string, any> = parse(xml);
console.log(foo.bar?.length);
FAQs
Type-safe xml paser and builder based in xsd for Typescript environments
The npm package typed-xml-builder receives a total of 1 weekly downloads. As such, typed-xml-builder popularity was classified as not popular.
We found that typed-xml-builder demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.