diff options
Diffstat (limited to 'lib/xmlreader.js')
| -rw-r--r-- | lib/xmlreader.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/xmlreader.js b/lib/xmlreader.js index f219d2b..551366f 100644 --- a/lib/xmlreader.js +++ b/lib/xmlreader.js @@ -85,6 +85,16 @@ function mapObject(input, valueFunc, keyFunc) { }, {}); } +var emptyElement = { + first: function() { + return null; + }, + firstOrEmpty: function() { + return emptyElement; + }, + attributes: {} +}; + function Element(name, attributes, children) { this.type = "element"; this.name = name; @@ -98,6 +108,10 @@ Element.prototype.first = function(name) { }); }; +Element.prototype.firstOrEmpty = function(name) { + return this.first(name) || emptyElement; +}; + Element.prototype.getElementsByTagName = function(name) { var elements = _.filter(this.children, function(child) { return child.name == name; |
