wezm.net/content/technical/2011/01/generating-xml-with-node-js.html

46 lines
1.7 KiB
HTML
Raw Permalink Normal View History

2011-01-27 19:57:51 +00:00
For a [node.js][node] project I'm working on I wanted to generate a [Sphinx
2011-01-28 17:45:05 +00:00
xmlpipe2][xmlpipe] data stream. The options for generating XML with node.js
2011-01-27 19:57:51 +00:00
seemed a bit limited. The main contender appeared to be [libmljs] but it
2011-01-28 17:45:05 +00:00
segfaulted whenever I tried to use it. So with previous experience using Tim Bray's [Genx][genx] C library I decided to write
2011-01-27 19:57:51 +00:00
bindings for node. The result is [node-genx], which is available via [npm].
npm install genx
2011-01-28 17:45:05 +00:00
[node]: http://nodejs.org/
[xmlpipe]: http://sphinxsearch.com/docs/manual-1.10.html#xmlpipe2
[libmljs]: https://github.com/polotek/libxmljs
2011-01-27 19:57:51 +00:00
[node-genx]: https://github.com/wezm/node-genx
2011-01-28 17:45:05 +00:00
[genx]: http://www.tbray.org/ongoing/When/200x/2004/02/20/GenxStatus
2011-01-27 19:57:51 +00:00
[npm]: http://npmjs.org/
Example Usage
-------------
2011-01-28 17:45:05 +00:00
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.
* jquery (1.4.4)
* jsdom (0.1.20)
* genx (0.8.0)
* node-uuid (1.1.0)
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
2011-01-27 19:57:51 +00:00
### 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.
2011-01-28 17:45:05 +00:00
<script src="https://gist.github.com/800580.js?file=xmlpipe2.js"></script>
2011-01-27 19:57:51 +00:00
### 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.
2011-01-28 17:45:05 +00:00
<script src="https://gist.github.com/796432.js?file=genx-atom.js"></script>