Coder Social home page Coder Social logo

node-xtraverse's Introduction

xtraverse

Build Coverage Dependencies

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

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

Traverse XML

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

Build XML

var feed = 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/>

node-xtraverse's People

Contributors

jaredhanson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.