README
xml-decorators
Decorators for xml serialization. Uses js2xmlparser under the hood.
Usage of decorators
import {XMLElement, XMLAttribute, XMLChild, xml} from 'xml-decorators';
const HOBBY_NS = 'h';
class Hobby {
@XMLAttribute({namespace: HOBBY_NS})
private name: string;
@XMLAttribute({namespace: HOBBY_NS})
private description: string;
}
const PERSON_ROOT = 'person';
const PERSON_NS = 'ps';
@XMLElement({root: PERSON_ROOT}) // optional
class Person {
@XMLAttribute({namespace: PERSON_NS})
private firstname: string;
private lastname: string;
@XMLAttribute({namespace: PERSON_NS})
get fullname(): string {
return this.firstname + ' ' + this.lastname;
}
@XMLAttribute({namespace: PERSON_NS})
private age: number;
@XMLChild({
namespace: PERSON_NS,
name: 'hobby'
})
private hobbies: Hobby[];
@XMLChild({
namespace: PERSON_NS,
stripPluralS: true
})
private friends: Person[];
@XMLChild({
name: 'pet',
implicitStructure: 'pets.