Generating XML With node.js - WezM.net by Wesley Moore
WezM.net

Generating XML With node.js

Published on

For a node.js project I’m working on I wanted to generate a Sphinx xmlpipe2 data stream. The options for generating XML with node.js seemed a bit limited. The main contender appeared to be libmljs but it segfaulted whenever I tried to use it. So with previous experience using Tim Bray’s Genx C library I decided to write bindings for node. The result is node-genx, which is available via npm.

npm install genx

Example Usage

Provided below are a couple of examples of using the genx module. To run them you will need the following modules, the version used at the time of writing is noted in brackets. The examples were developed against node.js v0.2.6.

These packages can be installed via npm. Note that jsdom is omitted from the list because it is a dependency of jquery:

npm install jquery genx node-uuid

xmlpipe2

In this example the first 10 Google search results for “node.js xml” are retrieved and converted into an xmlpipe2 stream, suitable for indexing with Sphinx.

Atom Feed

In this example, as in the former the first 10 Google search results for “node.js xml” are retrieved and converted into an Atom feed.

Comment icon Stay in touch!

Follow me on Twitter or Mastodon, subscribe to the feed, or send me an email.