Permalink
Browse files

doc

  • Loading branch information...
1 parent 0bd3a35 commit 14889c48115f68888b2a31f373af5478063bcdb8 @flosse flosse committed Jun 9, 2012
Showing with 6 additions and 9 deletions.
  1. +2 −2 README.markdown
  2. +4 −7 lib/element.js
View
@@ -47,8 +47,8 @@ Refer to `lib/parse.js` for the interface.
* `findNS(prefix?)`: search for xmlns of a prefix upwards
* `getChild(name, xmlns?)`: find first child
* `getChildren(name, xmlns?)`: find all children
-* `getChildByAttr(attr, value, xmlns?)`: find first child by a specific attribute
-* `getChildrenByAttr(attr, value, xmlns?)`: find all children by a specific attribute
+* `getChildByAttr(attr, value, xmlns?, recursive?)`: find first child by a specific attribute
+* `getChildrenByAttr(attr, value, xmlns?, recursive?)`: find all children by a specific attribute
* `getText()`: appends all text nodes recursively
* `getChildText(name)`: a child's text contents
* `root()`: uppermost parent in the tree
View
@@ -84,14 +84,14 @@ Element.prototype.getChildren = function(name, xmlns) {
};
/**
- * xmlns can be null
+ * xmlns and recursive can be null
**/
Element.prototype.getChildByAttr = function(attr, val, xmlns, recursive) {
return this.getChildrenByAttr(attr, val, xmlns, recursive)[0];
};
/**
- * xmlns can be null
+ * xmlns and recursive can be null
**/
Element.prototype.getChildrenByAttr = function(attr, val, xmlns, recursive) {
var result = [];
@@ -101,13 +101,10 @@ Element.prototype.getChildrenByAttr = function(attr, val, xmlns, recursive) {
child.attrs[attr] == val &&
(!xmlns || child.getNS() == xmlns))
result.push(child);
- if (recursive && child.getChildrenByAttr){
+ if (recursive && child.getChildrenByAttr)
result.push(child.getChildrenByAttr(attr, val, xmlns, true));
- }
- }
- if (recursive){
- result = [].concat.apply([], result);
}
+ if (recursive) result = [].concat.apply([], result);
return result;
};

0 comments on commit 14889c4

Please sign in to comment.