npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xml2xml-schema-change

v1.0.2

Published

Converts an xml file to a new xml file conforming to a different xsd schema

Downloads

1

Readme

xml2xml-schema-change

Ever needed a way to convert between xml schemas, then xml2xml-schema-change could be of use

NOTE: This package is a university project, and will unlikely be worked on in the future, so dont expect too much.

Description

A simple XML to XML converter, supporting a mapping file from one schema to the next. The package includes two primary methods.

xsltSchema: Which is used to initialise and create the conversion resources. This tool will primarily return a JSON object that can then be serialised and stored in a database for future use.

xsltTransformer: Which is used to perform a transformation on a xml file and return a xml file conforming to a different schema, this method utilised the JSON object received by the initialisation of xsltSchema

Installation

The simplest way to install xml2xml-schema-change is to use npm, just npm install xml2xml-schema-change which will download xml2js and all dependencies.

Usage

This is a simple tool to use though does require some understanding.

Stage ONE : Initialise

You will initialise the xsltSchema instance with 3 primary parameters.

  • xsd_source : This is a serialised version of the xsd that the parsed xml would be in
  • xsd_target : This is a serialised version of the xsd that you would require the returned xml to be in
  • mapping_object : This is a mapping object mapping the two together (read more on this later in this document)
const { xsltSchema } = require("xml2xml-schema-change")

const xslt_schema = new xsltSchema(xsd_source, xsd_target, mapping_object)
xslt_schema.init()
.then(()=>{
    const xslt_schema_serialised = JSON.stringify(xslt_schema, null, 2)
    // Can check what elements haven't been mapped to the xsd_target
    console.log(xslt_schema.non_mapped)
    // -> Save this xslt_schema_serialised in your database
}).catch((err) => {
    // Handle errors
    console.error(err);
});

Stage TWO : Transform

Once initialised, you can use the xslt_schema_serialised instance to transform a xml to the new xsd schema. You create an instance of the transformer with one paramiter:

  • xslt_schema_serialised : This is the stored instance from stage ONE

Then you call the transform method with one paramiter:

  • xml_source : This is a serialised version of the source xml you want to transform
const { xsltTransformer } = require("xml2xml-schema-change")

const xslt_transformer = new xsltTransformer(xslt_schema_serialised)
xslt_transformer.transform(xml_source)
.then((result) => {
    console.log(result)
    // -> Now do what you want with the transformed xml
})

Finished

Mapping Object

The mapping object should be as the form below. It is envisioned this mapping object would be created by an UI tool.

[
    {
        "target": "",
        "sources": []
    }
]
  • The primary array would hold objects of each mapping.
  • target : This is the target element of the xsd_target
  • sources : These are the Xpath sources from the xsd_source that will be getting mapped to the target.

Below a dummy example

[
    {
        "target": "bookstore",
        "sources": ["root/sold_novels", "root/available_novels"]
    }
]

What happens with multiple sources? Note i have only catered to concatenating strings and arrays

  • When a target is a string element, then the sources will be concatenated into one string.
    • As source_1 = "hello", source_2 = "world" -> concatenation = "hello world"
  • When the target is a array element, or an element with maxOccurs="unbounded", then the elements from the sources will just be instances of the array

Running tests, development

The development requirements are handled by npm, you just need to install them. We also have a number of unit tests, they can be run using npm test directly from the project root. Use of mocha.

Conclusion

There is no support for this package.