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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@neoimpulse/cap-js-xml-protocol

v1.0.5

Published

A CDS plugin to provide the xml protocol.

Readme

CDS XMLAdapter Plugin

This plugin for the SAP Cloud Application Programming Model (CAP) extends the default REST adapter to support XML payloads. It parses incoming XML data, converts it to JSON, and ensures compatibility with CAP's processing logic.

Features

  • Parses incoming XML payloads into JSON.
  • Converts Content-Type from application/xml to application/json for CAP compatibility.
  • Removes XML namespaces and attributes to create a clean JSON structure.
  • Converts boolean values correctly ("true"true, "false"false).
  • Returns appropriate error messages for invalid XML or unsupported content types.

Installation

To install the plugin, add it to your CAP project.

npm install cds-xmladapter-plugin

Usage

  1. Add the XMLAdapter to Your CAP Project

    Extend your CAP server to use the XMLAdapter.

    const cds = require("@sap/cds");
    const XMLAdapter = require("cds-xmladapter-plugin");
    
    cds.on("bootstrap", (app) => {
        app.use(new XMLAdapter().router);
    });
    
    module.exports = cds.server;
  2. Send XML Requests

    Use tools like Postman or custom clients to send requests with XML payloads. Ensure the Content-Type header is set to application/xml.

    Example XML payload:

    <ExchangeRate>
        <ID>123</ID>
        <Rate>10.5</Rate>
        <FromCurrency>EUR</FromCurrency>
        <ToCurrency>USD</ToCurrency>
        <IsValid>true</IsValid>
    </ExchangeRate>
  3. Handle XML Data in CAP

    The plugin automatically converts the XML to JSON, which can be processed by your CAP service logic.

How It Works

The plugin integrates with CAP's middleware pipeline and processes incoming requests as follows:

  1. Checks if the Content-Type is application/xml.
  2. Parses the XML payload into JSON using xml2js.
  3. Removes XML namespaces and attributes.
  4. Converts boolean values ("true"true, "false"false).
  5. Updates the Content-Type to application/json for compatibility with CAP services.
  6. Passes the parsed data to the next middleware in the chain.

If the Content-Type is not application/xml, it returns a 415 Unsupported Media Type error. For invalid XML payloads, it returns a 400 Bad Request error.

const cds = require("@sap/cds");
const { parseStringPromise } = require("xml2js");
const HttpAdapter = require("@sap/cds/lib/srv/protocols/http");

class XMLAdapter extends HttpAdapter {
    get router() {
        const router = super.router;

        router.use((req, res, next) => {
            if (req.method in { POST: 1, PUT: 1, PATCH: 1 } && req.headers["content-type"]) {
                if (!req.headers["content-type"].includes("application/xml")) {
                    res.status(415).json({ error: "Invalid content type. Expected 'application/xml'." });
                    return;
                }
            }
            next();
        });

        router.use((req, res, next) => {
            if (req.headers["content-type"] && req.headers["content-type"].includes("application/xml")) {
                let xmlBody = "";
                req.on("data", (chunk) => {
                    xmlBody += chunk.toString();
                });

                req.on("end", async () => {
                    try {
                        const jsonBody = await parseStringPromise(xmlBody, {
                            explicitArray: false,
                            ignoreAttrs: true,
                            tagNameProcessors: [(name) => name.replace(/^.*:/, "")],
                            valueProcessors: [
                                (value) => {
                                    if (value === "true") return true;
                                    if (value === "false") return false;
                                    return value;
                                },
                            ]
                        });

                        req.body = jsonBody;
                        req.headers["content-type"] = "application/json";
                        next();
                    } catch (err) {
                        res.status(400).json({ error: "Invalid XML format." });
                    }
                });
            } else {
                next();
            }
        });

        return router;
    }
}

module.exports = XMLAdapter;

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

Thanks to the SAP CAP community for their support and contributions.