Skip to content

Commit 8397398

Browse files
authored
Added descendantsNamed method to XmlElement prototype.
1 parent 088e2a7 commit 8397398

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lib/xmldoc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@
131131
}
132132
return undefined;
133133
};
134+
135+
XmlElement.prototype.descendantsNamed = function (name) {
136+
var matches = [];
137+
138+
for (var i = 0, l = this.children.length; i < l; i++) {
139+
var child = this.children[i];
140+
if (child.type === "element") {
141+
if (child.name === name) matches.push(child);
142+
matches = matches.concat(child.descendantsNamed(name));
143+
}
144+
}
145+
146+
return matches;
147+
};
134148

135149
XmlElement.prototype.descendantWithPath = function (path) {
136150
var descendant = this;

0 commit comments

Comments
 (0)