domDiff.js
/**
 * Calculates the difference between two given XML DOM nodes
  * criticalNodeNames - A string array containing node element names that are critical to the comparison. If there is a difference containing ANY of them, then it is the nodes are considered different regardless of other element similarity
 * @return diffCount - Number of different child nodes between the compared nodes
 *		   diffDegree - Value between 0 & 1 representing the percentage of difference between the compared nodes. Smaller values means more similar
 *		   diffIsInCriticalNodes - Whether the difference in the two nodes is found in the criticalNodeNames or not
 */
Calculates the difference between two given XML DOM nodes
criticalNodeNames - A string array containing node element names that are critical to the comparison. If there is a difference containing ANY of them, then it is the nodes are considered different regardless of other element similarity
@return diffCount - Number of different child nodes between the compared nodes
diffDegree - Value between 0 & 1 representing the percentage of difference between the compared nodes. Smaller values means more similar
diffIsInCriticalNodes - Whether the difference in the two nodes is found in the criticalNodeNames or not
Calculates the difference between two given XML DOM nodes criticalNodeNames - A string array containing node element names that are critical to the comparison . If there is a difference containing ANY of them then it is the nodes are considered different regardless of other element similarity @return diffCount - Number of different child nodes between the compared nodes diffDegree - Value between 0 & 1 representing the percentage of difference between the compared nodes . Smaller values means more similar diffIsInCriticalNodes - Whether the difference in the two nodes is found in the criticalNodeNames or not
function calcNodeDifference(existNode, modNode, criticalNodeNames)
{
	let diffIsInCriticalNodes = false; 
	let diff = compare(existNode, modNode).getDifferences(); 
	let diffNodeNames = underscore.pluck(diff, "node"); 
	for(let i = 0; i < criticalNodeNames.length && diffIsInCriticalNodes == false; i++)
	{
		for(let j = 0; j < diffNodeNames.length && diffIsInCriticalNodes == false; j++)
		{
			if(diffNodeNames[j].endsWith(criticalNodeNames[i]))
			{ 
				diffIsInCriticalNodes = true;
			}
		}
	}
	let diffDegree = (diff.length*2)/(existNode.childNodes.length + modNode.childNodes.length);
	log.debug({message: `existNode is ${diff.length} different from modNode. nodes have ${diffDegree} degree of difference, diffIsInCriticalNodes? ${diffIsInCriticalNodes}. Result: ${JSON.stringify(diff, null, 2)}`});
	return {"diffCount": diff.length, "diffDegree": diffDegree, "diffIsInCriticalNodes": diffIsInCriticalNodes};
}
function calcNodeDifference ( existNode , modNode , criticalNodeNames ) { let diffIsInCriticalNodes = false ; let diff = compare ( existNode , modNode ) . getDifferences ( ) ; let diffNodeNames = underscore . pluck ( diff , "node" ) ; for ( let i = 0 ; i < criticalNodeNames . length && diffIsInCriticalNodes == false ; i ++ ) { for ( let j = 0 ; j < diffNodeNames . length && diffIsInCriticalNodes == false ; j ++ ) { if ( diffNodeNames [ j ] . endsWith ( criticalNodeNames [ i ] ) ) { diffIsInCriticalNodes = true ; } } } let diffDegree = ( diff . length * 2 ) / ( existNode . childNodes . length + modNode . childNodes . length ) ; log . debug ( { message : ` ${ diff . length } ${ diffDegree } ${ diffIsInCriticalNodes } ${ JSON . stringify ( diff , null , 2 ) } ` } ) ; return { "diffCount" : diff . length , "diffDegree" : diffDegree , "diffIsInCriticalNodes" : diffIsInCriticalNodes } ; }
Calculates the difference between two given XML DOM nodes
 criticalNodeNames - A string array containing node element names that are critical to the comparison.
Calculates the difference between two given XML DOM nodes criticalNodeNames - A string array containing node element names that are critical to the comparison .
//indicator as to whether the difference found is in the critical nodes or not //Compare the two nodes and get the difference //fetch all the "node" properties from "diff" array //determine if any of the critical node names is in the list of differences //One of the critical node names was found in the list of outlined differences //degree of diff needs to be normalized between 0 & 1. diff.length contains the diff count and is multiplied by 2 since the we are comparing 2 nodes //denominator includes the total number of child nodes that each of the nodes being compared have