All Projects → PeculiarVentures → xml-core

PeculiarVentures / xml-core

Licence: MIT license
xml-core is a set of classes that make it easier to work with XML within the browser and node.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to xml-core

Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (+2205.56%)
Mutual labels:  schema, decorators
decapi
Create GraphQL API by decorating TypeScript classes
Stars: ✭ 81 (+350%)
Mutual labels:  schema, decorators
Type Graphql
Create GraphQL schema and resolvers with TypeScript, using classes and decorators!
Stars: ✭ 6,864 (+38033.33%)
Mutual labels:  schema, decorators
soap-typescript
SOAP decorators for creating wsdl's and annotating services to provide metadata for node-soap
Stars: ✭ 20 (+11.11%)
Mutual labels:  schema, decorators
Joiful
TypeScript Declarative Validation for Joi
Stars: ✭ 177 (+883.33%)
Mutual labels:  schema, decorators
magnet
A JSON/BSON schema generator
Stars: ✭ 16 (-11.11%)
Mutual labels:  schema
restgoose
Model-driven REST API framework using decorators
Stars: ✭ 28 (+55.56%)
Mutual labels:  decorators
knockout-decorators
Decorators for use Knockout JS in TypeScript and ESNext environments
Stars: ✭ 45 (+150%)
Mutual labels:  decorators
graphql-liftoff
Generate GraphQL schema language from API specifications and more
Stars: ✭ 44 (+144.44%)
Mutual labels:  schema
graphql-go-tools
Like apollo-tools for graphql-go
Stars: ✭ 22 (+22.22%)
Mutual labels:  schema
exodus
Migration tools for Tabular Data to Oracle JSON/Tabular Data
Stars: ✭ 19 (+5.56%)
Mutual labels:  schema
deco
Minimalist Function Decorators for Elixir
Stars: ✭ 21 (+16.67%)
Mutual labels:  decorators
metastore
A protobuf schema registry on steroids. It will keep track of the contracts throughout your organization, making sure no contract is broken.
Stars: ✭ 43 (+138.89%)
Mutual labels:  schema
dbmisc
Tools for working with databases in R
Stars: ✭ 24 (+33.33%)
Mutual labels:  schema
firestore-to-bigquery-export
NPM package for copying and converting Cloud Firestore data to BigQuery.
Stars: ✭ 26 (+44.44%)
Mutual labels:  schema
typeforce
Another biased type checking solution for Javascript
Stars: ✭ 22 (+22.22%)
Mutual labels:  schema
pysonDB
A Simple , ☁️ Lightweight , 💪 Efficent JSON based database for 🐍 Python. PysonDB-V2 has been released ⬇️
Stars: ✭ 293 (+1527.78%)
Mutual labels:  schema
djburger
Framework for safe and maintainable web-projects.
Stars: ✭ 75 (+316.67%)
Mutual labels:  decorators
go2gql
graphql-go schema generator by proto files
Stars: ✭ 33 (+83.33%)
Mutual labels:  schema
graphql-compose-dataloader
Add DataLoader to graphql-composer resolvers.
Stars: ✭ 18 (+0%)
Mutual labels:  schema

xml-core

xml-core is a set of classes that make it easier to work with XML within the browser and node.

license Test Coverage Status NPM version

NPM

Introduction

We wanted to be able to validate XAdES in the browser, specifically so we could validate the signature on the EU Trust List.

This lead us to the creation od XMLDSIGjs which allows us to validate XML and XAdESjs which extends it and enables us to validate XAdES signatures.

We use xml-core to make the creation of these libraries easier, we hope you may find it valuable in your own projects also.

Fundementally 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.

It is similar to xmljs but has a few differences -

  • Can convert the JSON back to XML,
  • Uses decorators to make enforcing schema in Javascript more natural.

Install

npm install xml-core

Using

ES5

var XmlCore = require("xml-core");

ES2015

import XmlCore from "xml-core";

Decrators

Information about decorators ES2015, TypeScript

XmlElement

Class decorator which allows to describe schema for xml element

Paramteres

Name Description
localName Sets a local name for xml element. Default value is name of Class
namespaceURI Sets a namespace URI for xml element. Default value is null
prefix Sets a prefix for xml element. Default value is null
parser Sets a parser as XmlObject for each child element of XmlCollection. Optional

XmlAttribute

Property decorator which allows to describe schema for attribute of xml element

Paramteres

Name Description
localName Sets a local name for xml element. Default value is name of Property
namespaceURI Sets a namespace URI for xml element. Default value is null
prefix Sets a prefix for attribute of xml element. Default value is null
defaultValue Sets a default value for attribute of xml element. Optional
required Determines if attribute of xml element is required. Default value is false
converter Sets a specific converter for attribute of xml element. Default is simple text

XmlChildElement

Property decorator which allows to describe schema for child element of xml element

Paramteres

Name Description
localName Sets local name for xml element. Default value is name of Class
namespaceURI Sets namespace URI for xml element. Default value is null
prefix Sets prefix for xml element. Default value is null
defaultValue Sets a default value for attribute of xml element. Optional
required Determines if child element is required. Default value is false
converter Sets a specific converter for child element. Default is simple text
parser Sets parser as XmlObject for child element. Optional
minOccurs Sets a min value for child element occurs. Default value is 0
maxOccurs Sets a max value for child element occurs. Default value is MAX
noRoot Determines if parser as XmlCollection must return it's children to parent element

XmlContent

Property decorator which allows to describe schema for content of xml element

Paramteres

Name Description
defaultValue Sets a default value for content of xml element. Optional
required Determines if content of xml element is required. Default value is false
converter Sets a specific converter for content of xml element. Default is simple text

XmlObject

Base class for XML elements.

LoadXml

Reads XML from string

LoadXml(node: Node | string): void;
static LoadXml(node: Node | string): this;

GetXml

Writes object to XML node

GetXml(): Node | null;

toString

Writes object to string

toString(): string;

Example

Target XML schema

<element name="Signature" type="ds:SignatureType"/>
<complexType name="SignatureType">
  <sequence>
    <element ref="ds:SignedInfo"/>
    <element ref="ds:SignatureValue"/>
    <element ref="ds:KeyInfo" minOccurs="0"/>
    <element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/>
  </sequence>
  <attribute name="Id" type="ID" use="optional"/>
</complexType>

TypeScript implementation of XML schema

import { XmlObject, XmlBase64Converter } from "xml-core";

@XmlElement({
    localName: "Signature",
    namespaceURI: "http://www.w3.org/2000/09/xmldsig#",
    prefix: "ds"
})
class Signature extends XmlObject {

    @XmlAttribute({
        localName: XmlSignature.AttributeNames.Id,
        defaultValue: "",
    })
    public Id: string;

    @XmlChildElement({
        parser: SignedInfo,
        required: true,
    })
    public SignedInfo: SignedInfo;

    @XmlChildElement({
        localName: "SignatureValue",
        namespaceURI: "http://www.w3.org/2000/09/xmldsig#",
        prefix: "ds",
        required: true,
        converter: XmlBase64Converter,
        defaultValue: null,
    })
    public SignatureValue: Uint8Array | null;

    @XmlChildElement({
        parser: KeyInfo
    })
    public KeyInfo: KeyInfo;

    @XmlChildElement({
        parser: DataObjects,
        noRoot: true
    })
    public ObjectList: DataObjects;

}

Using

const signature = new Signature();

// Read XML
signature.LoadXml(Signature.Parse('<ds:Signature Id="sigId">...</ds:signature>'));
console.log("Id:", signature.Id); // Id: sigId

// Write XML
signature.Id = "newId";
console.log(signature.toString()); // <ds:Signature Id="sigId">...</ds:signature>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].