[Pkg-javascript-commits] [ltx] 196/469: get child elements filtered by an attribute value

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:02:40 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit ed2a38fb135c23adfa286a2eee8faf8e01f210db
Author: Markus Kohlhase <mail at markus-kohlhase.de>
Date:   Sun Dec 18 16:06:23 2011 +0100

    get child elements filtered by an attribute value
---
 lib/element.js | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/lib/element.js b/lib/element.js
index 14d0c11..971724a 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -67,13 +67,14 @@ Element.prototype.findNS = function(prefix) {
 Element.prototype.getChild = function(name, xmlns) {
     return this.getChildren(name, xmlns)[0];
 };
+
 /**
  * xmlns can be null
  **/
 Element.prototype.getChildren = function(name, xmlns) {
     var result = [];
     for(var i = 0; i < this.children.length; i++) {
-	var child = this.children[i];
+	      var child = this.children[i];
         if (child.getName &&
             child.getName() == name &&
             (!xmlns || child.getNS() == xmlns))
@@ -82,6 +83,28 @@ Element.prototype.getChildren = function(name, xmlns) {
     return result;
 };
 
+/**
+ * xmlns can be null
+ **/
+Element.prototype.getChildByAttr = function(attr, val, xmlns) {
+    return this.getChildrenByAttr(attr, val, xmlns)[0];
+};
+
+/**
+ * xmlns can be null
+ **/
+Element.prototype.getChildrenByAttr = function(attr, val, xmlns) {
+    var result = [];
+    for(var i = 0; i < this.children.length; i++) {
+	      var child = this.children[i];
+        if (child.attrs &&
+            child.attrs[attr] == val &&
+            (!xmlns || child.getNS() == xmlns))
+            result.push(child);
+    }
+    return result;
+};
+
 Element.prototype.getText = function() {
     var text = "";
     for(var i = 0; i < this.children.length; i++) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list