@polyxml/node
v0.44.0
Published
High-performance, polyglot XML data-binding engine built in Rust
Maintainers
Readme
PolyXML Node.js & TypeScript Bindings
High-performance, polyglot streaming XML data-binding engine for Node.js and TypeScript.
- Precompiled native binaries for Linux (x86_64), macOS (Apple Silicon & Intel), and Windows (x64).
- Zero external native toolchain dependencies needed at runtime.
- Powered by the ultra-fast Rust
polyxml-coreengine and NAPI-RS.
Installation
npm install @polyxml/nodeUsage
const polyxml = require('@polyxml/node');
const schema = {
name: 'Book',
fields: [
{ name: 'id', xmlName: 'id', kind: 'attribute', scalarType: 'int' },
{ name: 'title', xmlName: 'title', kind: 'element', scalarType: 'string' },
{ name: 'price', xmlName: 'price', kind: 'element', scalarType: 'float' }
]
};
const xml = '<Book id="42"><title>Rust in Action</title><price>39.99</price></Book>';
const book = polyxml.deserialize(xml, schema);
console.log(book);
// { id: 42, title: 'Rust in Action', price: 39.99 }Nested Schemas, Lists & xsi:type Polymorphism
FieldDefinition supports nestedSchema, isList, and required, while
ModelSchema supports xmlName, isAbstract, and variants for full
complex-type hierarchies and xsi:type round-trips:
const shipmentSchema = {
name: 'Shipment',
fields: [
{
name: 'destination',
xmlName: 'destination',
kind: 'element',
required: true,
nestedSchema: {
name: 'Address',
fields: [
{ name: 'city', xmlName: 'city', kind: 'element', scalarType: 'string', required: true },
],
},
},
{
name: 'vehicles',
xmlName: 'vehicle',
kind: 'element',
isList: true,
nestedSchema: {
name: 'Vehicle',
isAbstract: true,
variants: [
{
name: 'Car',
fields: [
{ name: 'id', xmlName: 'id', kind: 'element', scalarType: 'string' },
{ name: 'doors', xmlName: 'doors', kind: 'element', scalarType: 'int' },
],
},
],
fields: [{ name: 'id', xmlName: 'id', kind: 'element', scalarType: 'string' }],
},
},
],
};License
MIT
