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

express-xml-domparser

v0.0.3

Published

Express middleware to read in the body of an XML http request into a DOM

Downloads

6

Readme

express-xml-domparser

For those rare cases when you want to make a DOM out of incoming raw xml-body requests. This middleware works with any connect- or express-based nodejs application.

Description

Admittedly, having to deal with XML data has become less common in recent years. Still, there are services and APIs using this format. The middleware is based on the [xml-dom-bodyparser middleware] (https://github.com/macedigital/express-xml-bodyparser) as a blueprint.

There were several features that express-xml-bodyparser calls out and here is how express-xml-domparser deals with them:

  • REMOVED: custom configuration options how to deal with xml data, since it was almost all related to xml->json conversion
  • KEPT: Attempt to parse data only once, even if middleware is called multiple times.
  • KEPT: Skip data parsing immediately if no req-body has been sent.
  • KEPT: Accept any XML-based content-type, e.g. application/rss+xml
  • KEPT: No dependency on coffeescript keeping dependencies to a minimum.

Installation

Utilize npm by typing npm install express-xml-domparser --save in your projects root folder and you are good to go.

Dependencies

Uses the libxmljs npm package as its XML parser.

Usage

You can either use express-xml-domparser at application level, or for specific routes only.

Here is an example of an express application with default settings:

var express = require('express'),
    app = express(),
    http = require('http'),
    server = http.createServer(app),
    xmldomparser = require('express-xml-domparser');

// .. other middleware ...
app.use(express.json());
app.use(express.urlencoded());
app.use(xmldomparser());
// ... other middleware ...

app.post('/receive-xml', function(req, res, next) {

  // req.rawData contains the parsed xml
  // req.xmlDom contains the DOM

});

server.listen(1337);

If you wanted to use express-xml-bodyparser for specific routes only, you would do something like this:

app.post('/receive-xml', xmldomparser(), function(req, res, next) {
  // check req.body
});

Extensions to the http.ClientRequest (req) Object

This middleware adds 2 properties to the request object:

  • req.rawBody: contains the raw data read in from the request, without any processing done to it
  • req.xmlDom: the libxmljs XML DOM Document returned by parsing the raw data read from the request

Usage Warnings

As this is processing the data events 'on' and 'end', it may conflict with other middleware (connect.bodyParser for example) that also process the same data events. Be careful if you try to use 2 body parsers. Also note that several different connect/express middleware attempts to expose req.rawBody as well in an attempt to reproduce early express behavior.