I'm stucked with the following function, trying to get back a value (a part of a dom tree).
Instead of receiving a useful value I just obtain a 0/undefined.
var findNodeForAttributeValue = function (node, innerXmlAttributeName, innerXmlAttributeValue) {
var indirectReturnVar='0';
if ((node.nodeType === 1)&&(node.hasAttribute(innerXmlAttributeName))) {
if (node.getAttribute(innerXmlAttributeName)==innerXmlAttributeValue) {
indirectReturnVar=node;
return indirectReturnVar;
}
}
if((node.hasChildNodes())&&(node.firstChild!=null)) {
Array.forEach ( node.childNodes, function (children) {
findNodeForAttributeValue(children, innerXmlAttributeName, innerXmlAttributeValue);
} );
return indirectReturnVar;
}
Edit
Updated code:
var findNodeForAttributeValue = function (node, innerXmlAttributeName, innerXmlAttributeValue) {
var indirectReturnVar='0';
if ((node.nodeType === 1) && (node.hasAttribute(innerXmlAttributeName))) {
if (node.getAttribute(innerXmlAttributeName) == innerXmlAttributeValue) {
indirectReturnVar = node;
return indirectReturnVar;
}
}
if ((node.hasChildNodes()) && (node.firstChild != null)) {
for (var fi=0, fiLen=node.childNodes.length; fi<fiLen; fi++) {
findNodeForAttributeValue(node.childNodes[fi], innerXmlAttributeName, innerXmlAttributeValue);
}
return indirectReturnVar;
}
}