{"id":18601587,"url":"https://github.com/peculiarventures/xml-core","last_synced_at":"2025-04-10T19:30:40.741Z","repository":{"id":14643031,"uuid":"73409321","full_name":"PeculiarVentures/xml-core","owner":"PeculiarVentures","description":"xml-core is a set of classes that make it easier to work with XML within the browser and node.","archived":false,"fork":false,"pushed_at":"2023-01-07T04:50:37.000Z","size":536,"stargazers_count":19,"open_issues_count":14,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-14T12:36:36.188Z","etag":null,"topics":["decorators","schema","typescript","xml"],"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/PeculiarVentures.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-11-10T18:24:22.000Z","updated_at":"2023-02-28T15:12:08.000Z","dependencies_parsed_at":"2023-01-13T18:02:43.909Z","dependency_job_id":null,"html_url":"https://github.com/PeculiarVentures/xml-core","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fxml-core","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fxml-core/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fxml-core/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fxml-core/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeculiarVentures","download_url":"https://codeload.github.com/PeculiarVentures/xml-core/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281395,"owners_count":21077423,"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","schema","typescript","xml"],"created_at":"2024-11-07T02:08:48.429Z","updated_at":"2025-04-10T19:30:40.431Z","avatar_url":"https://github.com/PeculiarVentures.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# xml-core\n\n`xml-core` is a set of classes that make it easier to work with XML within the browser and node.\n\n[![license](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/PeculiarVentures/xml-core/master/LICENSE)\n[![Test](https://github.com/PeculiarVentures/xml-core/actions/workflows/test.yml/badge.svg)](https://github.com/PeculiarVentures/xml-core/actions/workflows/test.yml)\n[![Coverage Status](https://coveralls.io/repos/github/PeculiarVentures/xml-core/badge.svg?branch=master)](https://coveralls.io/github/PeculiarVentures/xml-core?branch=master)\n[![NPM version](https://badge.fury.io/js/xml-core.png)](http://badge.fury.io/js/xml-core)\n\n[![NPM](https://nodei.co/npm/xml-core.png)](https://nodei.co/npm/xml-core/)\n\n\n## Introduction\n\nWe wanted to be able to validate [XAdES](https://en.wikipedia.org/wiki/XAdES) in the browser, specifically so we could validate the signature on the [EU Trust List](https://github.com/PeculiarVentures/tl-create).\n\n\nThis lead us to the creation od [XMLDSIGjs](https://github.com/PeculiarVentures/xmldsigjs) which allows us to validate XML and [XAdESjs](https://github.com/PeculiarVentures/xadesjs) which extends it and enables us to validate XAdES signatures.\n\nWe use `xml-core` to make the creation of these libraries easier, we hope you may find it valuable in your own projects also. \n\nFundementally `xml-core` provides a way to transform XML to JSON and JSON to XML, which enables you to enforce a schema on the associated XML. The goal of this is to let you work naturally with XML in Javascript.\n\nIt is similar to [xmljs](https://www.npmjs.com/package/xmljs) but has a few differences -\n- Can convert the JSON back to XML,\n- Uses [decorators](https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.61eut6wa9) to make enforcing schema in Javascript more natural. \n\n## Install\n\n```\nnpm install xml-core\n```\n\n## Using\n\n### ES5\n\n```javascript\nvar XmlCore = require(\"xml-core\");\n```\n\n### ES2015\n\n```javascript\nimport XmlCore from \"xml-core\";\n```\n\n## Decrators\n\nInformation about decorators [ES2015](https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841#.qnl62mocp), [TypeScript](https://www.typescriptlang.org/docs/handbook/decorators.html)\n\n### XmlElement\n\nClass decorator which allows to describe schema for xml element\n\n__Paramteres__\n\n| Name | Description |\n|:----------------|:--------------------------------------------------------------------------------| \n| localName       | Sets a local name for xml element. Default value is name of Class               |\n| namespaceURI    | Sets a namespace URI for xml element. Default value is `null`                   |\n| prefix          | Sets a prefix for xml element. Default value is `null`                          |\n| parser          | Sets a parser as `XmlObject` for each child element of `XmlCollection`. Optional|\n\n### XmlAttribute\n\nProperty decorator which allows to describe schema for attribute of xml element\n\n__Paramteres__\n\n| Name | Description |\n|:----------------|:--------------------------------------------------------------------------------| \n| localName       | Sets a local name for xml element. Default value is name of Property            |\n| namespaceURI    | Sets a namespace URI for xml element. Default value is `null`                   |\n| prefix          | Sets a prefix for attribute of xml element. Default value is `null`             |\n| defaultValue    | Sets a default value for attribute of xml element. Optional                     |\n| required        | Determines if attribute of xml element is required. Default value is `false`    |\n| converter       | Sets a specific converter for attribute of xml element. Default is simple text  |\n\n\n### XmlChildElement\n\nProperty decorator which allows to describe schema for child element of xml element\n\n__Paramteres__\n\n| Name | Description |\n|:----------------|:--------------------------------------------------------------------------------| \n| localName       | Sets local name for xml element. Default value is name of Class                 |\n| namespaceURI    | Sets namespace URI for xml element. Default value is `null`                     |\n| prefix          | Sets prefix for xml element. Default value is `null`                            |\n| defaultValue    | Sets a default value for attribute of xml element. Optional                     |\n| required        | Determines if child element is required. Default value is `false`               |\n| converter       | Sets a specific converter for child element. Default is simple text             |\n| parser          | Sets parser as `XmlObject` for child element. Optional                          |\n| minOccurs       | Sets a min value for child element occurs. Default value is `0`                 |\n| maxOccurs       | Sets a max value for child element occurs. Default value is `MAX`               |\n| noRoot          | Determines if parser as `XmlCollection` must return it's children to parent element |\n\n### XmlContent\n\nProperty decorator which allows to describe schema for content of xml element\n\n__Paramteres__\n\n| Name | Description |\n|-----------------|---------------------------------------------------------------------------------| \n| defaultValue    | Sets a default value for content of xml element. Optional                       |\n| required        | Determines if content of xml element is required. Default value is `false`      |\n| converter       | Sets a specific converter for content of xml element. Default is simple text    |\n\n## XmlObject\n\nBase class for XML elements.\n\n### LoadXml\n\nReads XML from string\n\n```typescript\nLoadXml(node: Node | string): void;\nstatic LoadXml(node: Node | string): this;\n```\n\n### GetXml\n\nWrites object to XML node\n\n```typescript\nGetXml(): Node | null;\n```\n\n### toString\n\nWrites object to string\n\n```\ntoString(): string;\n```\n\n__Example__\n\nTarget XML [schema]()\n\n```xml\n\u003celement name=\"Signature\" type=\"ds:SignatureType\"/\u003e\n\u003ccomplexType name=\"SignatureType\"\u003e\n  \u003csequence\u003e\n    \u003celement ref=\"ds:SignedInfo\"/\u003e\n    \u003celement ref=\"ds:SignatureValue\"/\u003e\n    \u003celement ref=\"ds:KeyInfo\" minOccurs=\"0\"/\u003e\n    \u003celement ref=\"ds:Object\" minOccurs=\"0\" maxOccurs=\"unbounded\"/\u003e\n  \u003c/sequence\u003e\n  \u003cattribute name=\"Id\" type=\"ID\" use=\"optional\"/\u003e\n\u003c/complexType\u003e\n```\n\nTypeScript implementation of XML schema\n\n```typescript\nimport { XmlObject, XmlBase64Converter } from \"xml-core\";\n\n@XmlElement({\n    localName: \"Signature\",\n    namespaceURI: \"http://www.w3.org/2000/09/xmldsig#\",\n    prefix: \"ds\"\n})\nclass Signature extends XmlObject {\n\n    @XmlAttribute({\n        localName: XmlSignature.AttributeNames.Id,\n        defaultValue: \"\",\n    })\n    public Id: string;\n\n    @XmlChildElement({\n        parser: SignedInfo,\n        required: true,\n    })\n    public SignedInfo: SignedInfo;\n\n    @XmlChildElement({\n        localName: \"SignatureValue\",\n        namespaceURI: \"http://www.w3.org/2000/09/xmldsig#\",\n        prefix: \"ds\",\n        required: true,\n        converter: XmlBase64Converter,\n        defaultValue: null,\n    })\n    public SignatureValue: Uint8Array | null;\n\n    @XmlChildElement({\n        parser: KeyInfo\n    })\n    public KeyInfo: KeyInfo;\n\n    @XmlChildElement({\n        parser: DataObjects,\n        noRoot: true\n    })\n    public ObjectList: DataObjects;\n\n}\n```\n\n__Using__\n\n```typescript\nconst signature = new Signature();\n\n// Read XML\nsignature.LoadXml(Signature.Parse('\u003cds:Signature Id=\"sigId\"\u003e...\u003c/ds:signature\u003e'));\nconsole.log(\"Id:\", signature.Id); // Id: sigId\n\n// Write XML\nsignature.Id = \"newId\";\nconsole.log(signature.toString()); // \u003cds:Signature Id=\"sigId\"\u003e...\u003c/ds:signature\u003e\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeculiarventures%2Fxml-core","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeculiarventures%2Fxml-core","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeculiarventures%2Fxml-core/lists"}