allows transparent XML <-> Object conversion in typescript
Needs typescript-rtti to retrieve type at runtime.
To build something that relies in xml-model with vite
``typescript
import { defineConfig } from "vite";
import XMLModelVitePlugin from "xml-model/vite";
export default defineConfig({
plugins: [
// see options in JSDoc
XMLModelVitePlugin(),
],
// ... rest of the config
});
`
`typescript
import "reflect-metadata";
import { Model, getModel, XML } from "xml-model";
@Model({
fromXML(ctx) {
const instance = new MyClass();
if (ctx.properties.foo) instance.foo = ctx.properties.foo;
return instance;
},
})
class MyClass {
foo = "bar";
}
const model = getModel(MyClass);
const a: MyClass = model.fromXML("
console.log(JSON.stringify(a)); // {"foo":"test"}
const b = new MyClass();
console.log(XML.stringify(model.toXML(b))); //
b.foo = "other";
console.log(XML.stringify(model.toXML(b))); //
``
See source code for more