:: Forum >> Version 1 >>

Question on reusing code of the forum

Hello Alex!

Some time ago there was a forum posting where the code for the selectNodes and selectSingleNode emulation was posted by you.

Is this snippet copyrighted or where is it derived from?

The Forum message was:

/javascript.forum.4524.20/new-bug-with-firefox-1.html

if (window.XPathEvaluator) {

    var 
xpath = new XPathEvaluator();

    var 
element Element.prototype;
    var 
attr Attr.prototype;
    var 
doc Document.prototype;

    
delete element.text;
    
delete attr.text;

    
element.selectNodes = function (path) {
        var 
result xpath.evaluate(paththisthis.ownerDocument._ns7null);
        var 
inodes = [];
        for (
i=0i<result.snapshotLengthi++) {
            
nodes[i] = result.snapshotItem(i);
            
nodes[i].text nodes[i].firstChild ? nodes[i].firstChild.nodeValue "";
        }
        return 
nodes;
    };

    
element.selectSingleNode = function (path) {
       var 
node xpath.evaluate(paththisthis.ownerDocument._ns9null).singleNodeValue;
       
dump('element.selectSingleNode(path): ' path '\n');
       if ( 
node != null node.text node.firstChild ? node.firstChild.nodeValue "";
       return 
node;
    };

    
doc.selectSingleNode = function (path) {
        
dump('doc.selectSingleNode(path): ' path '\n');
        var 
node xpath.evaluate(paththisthis._ns9null).singleNodeValue;
        if ( 
node != null node.text node.firstChild ? node.firstChild.nodeValue "";
        return 
node;
    };

    
doc.selectNodes = function (path) {
        var 
result xpath.evaluate(paththisthis._ns7null);
        var 
inodes = [];
        for (
i=0i<result.snapshotLengthi++) {
            
nodes[i] = result.snapshotItem(i);
            
nodes[i].text nodes[i].firstChild ? nodes[i].firstChild.nodeValue "";
        }
        return 
nodes;
    };

}  
Can I use the code for something else (project which is published under the LGPL)?

Pleas give me a short feedback.

Thank you.

Best Regards...
Dietrich
Wednesday, November 30, 2005
Dietrich,

this is the original code which was released as part of ActiveWidgets 1.0 under GPL and ActiveWidgets commercial license. So you can use it freely under GPL terms (but not LGPL).
Alex (ActiveWidgets)
Wednesday, November 30, 2005
Thank you for answering.

Just for your interrest: Here is a code part which uses nearly the same code and claims to be copyright by Microsoft:

http://research.microsoft.com/users/som/blog/AtlasCompat.htm

function selectNodes(doc,path,c){
    var 
xpath =new XPathEvaluator();
    var 
result =xpath.evaluate(path,doc.documentElement,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
    var 
nodeList =new Array();
    for(var 
=0;<result.snapshotLength;i++){
      
nodeList.add(result.snapshotItem(i));
    }
    return 
nodeList;
  }
  function 
selectSingleNode(doc,path,c){
    
path +='[1]';
    var 
nodes =selectNodes(doc,path,c);
    if (
nodes.length !=0){
      return 
nodes[0];
    }
    else {
      return 
null;
    }
  }
  
w.XMLDocument.prototype.selectNodes =function(path){
    return 
selectNodes(this,path,this);
  }
  
w.XMLDocument.prototype.selectSingleNode =function(path){
    return 
selectSingleNode(this,path,null);
  }
 
And here is my code part which I want to give to a lgpl project. Maybe you rethink allowing me to use the code?


if (window.XPathEvaluator) {

  var 
xpath = new XPathEvaluator();

  if (!
Element.prototype.selectSingleNode) {
    
Element.prototype.selectSingleNode = function (path) {
      return 
xpath.evaluate(paththisthis.ownerDocument._nsXPathResult.FIRST_ORDERED_NODE_TYPEnull).singleNodeValue;
    };
  }
  
  if (!
Element.prototype.selectNodes) {
    
Element.prototype.selectNodes = function (path) {
      var 
result xpath.evaluate(paththisthis.ownerDocument._nsXPathResult.ORDERED_NODE_SNAPSHOT_TYPEnull);
      var 
inodes = [];
  
      for (
i=0i<result.snapshotLengthi++) {
        
nodes[i] = result.snapshotItem(i);
      };
  
      return 
nodes;
    };
  }
  
  if (!
Document.prototype.selectSingleNode) {
    
Document.prototype.selectSingleNode = function (path) {
      return 
xpath.evaluate(paththisthis._nsXPathResult.FIRST_ORDERED_NODE_TYPEnull).singleNodeValue;
    };
  }
  
  if (!
Document.prototype.selectNodes) {
    
Document.prototype.selectNodes = function (path) {
      var 
result xpath.evaluate(paththisthis._nsXPathResult.ORDERED_NODE_SNAPSHOT_TYPEnull);
      var 
inodes = [];

      for (
i=0i<result.snapshotLengthi++) {
        
nodes[i] = result.snapshotItem(i);
      };
      
      return 
nodes;
    };
  }

  
Element.prototype.__defineGetter__('text',
    function() {
      var 
text '';
        for (var 
i=0i<this.childNodes.lengthi++) {
          
text += this.childNodes[i].text;
        };
        return 
text;
    }
  );
  
  
Element.prototype.__lookupGetter__('text');

  
Attr.prototype.__defineGetter__('text', function(){return this.nodeValue});
  
Attr.prototype.__lookupGetter__('text');

  
Text.prototype.__defineGetter__('text', function(){return this.nodeValue});
  
Text.prototype.__lookupGetter__('text');
  
}
 
Dietrich
Wednesday, November 30, 2005
Dietrich,

this is very common functionality so I am not surprised there are many similar implementations. I just wanted to say that AW code is the original one (not copied from somewhere).

In your case - I think this functionality is very simple and can be re-implemented in 10 minutes. However copying parts of AW code into LGPL project is NOT ok.
Alex (ActiveWidgets)
Wednesday, November 30, 2005
OK.

So to clarify it, please just say yes or no to the last code block.

Thank you...
Dietrich
Wednesday, November 30, 2005
Yes.
Alex (ActiveWidgets)
Wednesday, November 30, 2005



This topic is archived.

Back to support forum

Forum search