﻿    
    if( document.implementation.hasFeature("XPath", "3.0")){
       
        XMLDocument.prototype.selectNodes = function( cXPathString, xNode){
        
            var oNSResolver;
            var aItems;
            var aResult;
        
            if( ! xNode) xNode = this;
            
            oNSResolver = this.createNSResolver( this.documentElement);
            aItems = this.evaluate( cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
            aResult = [];
            
            for( i = 0; i < aItems.snapshotLength; i ++){
            
                aResult[i] = aItems.snapshotItem(i);
            }
    
            return aResult;
        }
    
        Element.prototype.selectNodes = function( cXPathString){
        
            if( this.ownerDocument.selectNodes){
        
                return this.ownerDocument.selectNodes( cXPathString, this);
            }
            
            else{
                
                throw "For XML Elements Only";
            }
        
        }
    
    }

    if( document.implementation.hasFeature( "XPath", "3.0")){

        XMLDocument.prototype.selectSingleNode = function( cXPathString, xNode){

            var xItems;

            if( ! xNode) xNode = this;
            
            xItems = this.selectNodes( cXPathString, xNode);
            
            if( xItems.length > 0){
                
                return xItems[0];
            
            }
            
            else{
    
                return null;
    
            }

        }

        Element.prototype.selectSingleNode = function( cXPathString){ 
            
            if( this.ownerDocument.selectSingleNode){
            
                return this.ownerDocument.selectSingleNode( cXPathString, this);
            
            }
            
            else{
                
                throw "For XML Elements Only";
            
            }
        }
    }
   