Skip to content

Repository files navigation

xtraverse

BuildCoverageDependencies

Simplified traversal and building of an XML DOM.

This module provides a jQuery-like wrapper, but geared for traversing and manipulating an XML DOM, as opposeed to an HTML DOM. The API aims to be compatible with Strophe.js' Builder and Less-Than XML. The underlying DOM is W3C standard, provided by XMLDOM.

Install

$ npm install xtraverse

Usage

Parse XML

varxml=fs.readFileSync('feed.xml','utf8');varfeed=XT(xml);

Traverse XML

console.log(feed.children('title').text());for(varlink=feed.children().first('link');link.length>0;link=link.next('link')){console.log(link.attr('href'));}for(varentry=feed.children().first('entry');entry.length>0;entry=entry.next('entry')){console.log('Entry: '+entry.children('title').text());}

Build XML

varfeed=XT('<feed xmlns="http://www.w3.org/2005/Atom"/>').c('title').t('Example Feed').up().c('link',{href: 'http://example.org/'}).c('entry').c('title').t('Atom-Powered Robots Run Amok').up().up().c('entry').c('title').t('Today I Ate Pancakes');

Tests

$ npm install
$ npm test

Credits

License

The MIT License

Copyright (c) 2013 Jared Hanson <http://jaredhanson.net/>

About

Wrapper for simplifying XML traversal.

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages