pto-assignments
Version:
Library and CLI tool for parsing USPTO assignment data
41 lines (27 loc) • 790 B
JavaScript
var xmldoc = require('xmldoc');
var Parser = module.exports = function(xml) {
this.doc = new xmldoc.XmlDocument(xml);
this.cache = {};
};
Parser.prototype.text = function(path, options) {
if (!options) options = {};
if (!options.key) options.key = 'val';
var value = this.doc.descendantWithPath(path)[options.key];
if (options.post) {
value = options.post(value);
}
return value;
};
Parser.prototype.attribute = function(attribute, options) {
var e = this.doc;
if (options && options.path)
e = this.doc.descendantWithPath(options.path);
var val = e.attr[attribute];
if (options && options.post) {
val = options.post(val);
}
return val;
};
Parser.prototype.set = function(path) {
return this.doc.descendantWithPath(path);
};