{"id":17230083,"url":"https://github.com/robinbuschmann/xml-typescript","last_synced_at":"2025-04-14T02:31:25.734Z","repository":{"id":49379055,"uuid":"75714655","full_name":"RobinBuschmann/xml-typescript","owner":"RobinBuschmann","description":"Decorators for xml serialization","archived":false,"fork":false,"pushed_at":"2022-07-25T07:49:06.000Z","size":66,"stargazers_count":21,"open_issues_count":11,"forks_count":19,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-29T15:06:28.658Z","etag":null,"topics":["decorators","xml-serialization"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RobinBuschmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-06T09:14:29.000Z","updated_at":"2024-03-29T09:36:47.000Z","dependencies_parsed_at":"2022-09-04T12:52:48.935Z","dependency_job_id":null,"html_url":"https://github.com/RobinBuschmann/xml-typescript","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxml-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxml-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxml-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RobinBuschmann%2Fxml-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RobinBuschmann","download_url":"https://codeload.github.com/RobinBuschmann/xml-typescript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248810883,"owners_count":21165195,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decorators","xml-serialization"],"created_at":"2024-10-15T04:52:24.116Z","updated_at":"2025-04-14T02:31:23.821Z","avatar_url":"https://github.com/RobinBuschmann.png","language":"TypeScript","readme":"[![Build Status](https://travis-ci.org/RobinBuschmann/xml-typescript.png?branch=master)](https://travis-ci.org/RobinBuschmann/xml-typescript)\n\n[![Dependencies status](https://david-dm.org/RobinBuschmann/xml-typescript.svg)](https://david-dm.org/RobinBuschmann/xml-typescript.svg)\n\n# xml-decorators\n\nDecorators for xml serialization. Uses [js2xmlparser](https://www.npmjs.com/package/js2xmlparser)\nunder the hood.\n\n## Usage of decorators\n\n```typescript\nimport {XMLElement, XMLAttribute, XMLChild, xml} from 'xml-decorators';\n\nconst HOBBY_NS = 'h';\n\nclass Hobby {\n\n  @XMLAttribute({namespace: HOBBY_NS})\n  private name: string;\n\n  @XMLAttribute({namespace: HOBBY_NS})\n  private description: string;\n}\n\nconst PERSON_ROOT = 'person';\nconst PERSON_NS = 'ps';\n\n@XMLElement({root: PERSON_ROOT}) // optional\nclass Person {\n\n  @XMLAttribute({namespace: PERSON_NS})\n  private firstname: string;\n\n  private lastname: string;\n\n  @XMLAttribute({namespace: PERSON_NS})\n  get fullname(): string {\n\n    return this.firstname + ' ' + this.lastname;\n  }\n\n  @XMLAttribute({namespace: PERSON_NS})\n  private age: number;\n\n  @XMLChild({\n    namespace: PERSON_NS,\n    name: 'hobby'\n  })\n  private hobbies: Hobby[];\n\n  @XMLChild({\n    namespace: PERSON_NS,\n    stripPluralS: true\n  })\n  private friends: Person[];\n\n  @XMLChild({\n    name: 'pet',\n    implicitStructure: 'pets.$'\n  })\n  private pets: string[];\n  \n }\n```\n\n## Serialization\n```typescript\nconst hobbies = [\n  new Hobby('reading', 'loves to read books, magazines and web articles'),\n  new Hobby('listening to Music', 'loves to listen to rock music'),\n  new Hobby('travelling', 'loves to travel around the world'),\n];\nconst pets = ['dog', 'cat'];\nconst bob = new Person('Bob', 'Mad', 29, hobbies, pets);\n\nconst bobXml = xml.serialize(bob);\n```\n\nOr if you want to override the root tag name or did not used the `@XMLElement` annotation.\n```typescript\nconst bob2Xml = xml.serialize('great-person', bob);\n```\n\n### Result\n```xml\n\u003c?xml version='1.0'?\u003e\n\u003cgreat-person ps:firstname='Bob' ps:fullname='Bob Mad' ps:age='29'\u003e\n    \u003cps:hobby h:name='reading' h:description='loves to read books, magazines and web articles'/\u003e\n    \u003cps:hobby h:name='listening to Music' h:description='loves to listen to rock music'/\u003e\n    \u003cps:hobby h:name='travelling' h:description='loves to travel around the world'/\u003e\n    \u003cpets\u003e\n        \u003cpet\u003edog\u003c/pet\u003e\n        \u003cpet\u003ecat\u003c/pet\u003e\n    \u003c/pets\u003e\n\u003c/great-person\u003e\n```\n\n### Async\n```typescript\nxml\n  .serializeAsync(bob)\n  .then(bobXml =\u003e console.log(bobXml))\n  ;\n```\n\n## Schema\nIf you want to retrieve the \"js2xmlparser\" schema instead:\n```typescript\nxml.getSchema(bob);\nxml.getSchemaAsync(bob).then(/* */);\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinbuschmann%2Fxml-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobinbuschmann%2Fxml-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobinbuschmann%2Fxml-typescript/lists"}