Overall: When I attempt to use the insertBefore method I get an error "Insert position node must be a child of the node to insert under." Below I walk through my code explaining what I am doing. Any help would be grealy appreciated.
//this is just to show that I am working with two different XMl files. One to clone a node from and the other to actually insert into.
objBatchDoc = objBatch.documentElement;
objBatchTemplateDoc = objTemplateBatch.documentElement;
//Here I am a getting a node from another file with the same structure and then cloning it. It will be used as the new node I need to insert
temp = "MasterRecipe/RecipeElement";
var objMasterMainNode = objBatchTemplateDoc.selectSingleNode(temp);
if (objMasterMainNode == null) {
alert('object is nul');
} else {
var objHoldingNode = objMasterMainNode.cloneNode(true);
//end getting new node, next I am setting some initial values for this cloned node.
objHoldingNode.selectSingleNode('ID').text = ElementName;
objHoldingNode.selectSingleNode('Description').text = ElementDesc;
//next I point to the node where I want the new node to be inserted above and it does pull back a node.
temp = "MasterRecipe[ID='" + RecipeID + "']/RecipeElement/RecipeElement/RecipeElement[ID='" + CurrentNodeID + "']";
var objBatchCurrent = objBatchDoc.selectSingleNode(temp);
//next I want to get the parent of the node above to be used in the insertBefore function.
var temp2 = "MasterRecipe[ID='" + RecipeID + "']/RecipeElement/RecipeElement";
var objBatchCurrentPlusOne;
objBatchCurrentPlusOne = objBatchDoc.selectSingleNode(temp2);
//next I attempt to insert the node. But I get an error "Insert position node must be a child of the node to insert under" on the insertBefore Function. Please help I can't seem to figure what I am doing wrong.
if (objBatchCurrentPlusOne == null) {
}else{
objBatchCurrentPlusOne.insertBefore(objHoldingNode, objBatchCurrent);
}
//this is just to show that I am working with two different XMl files. One to clone a node from and the other to actually insert into.
objBatchDoc = objBatch.documentElement;
objBatchTemplateDoc = objTemplateBatch.documentElement;
//Here I am a getting a node from another file with the same structure and then cloning it. It will be used as the new node I need to insert
temp = "MasterRecipe/RecipeElement";
var objMasterMainNode = objBatchTemplateDoc.selectSingleNode(temp);
if (objMasterMainNode == null) {
alert('object is nul');
} else {
var objHoldingNode = objMasterMainNode.cloneNode(true);
//end getting new node, next I am setting some initial values for this cloned node.
objHoldingNode.selectSingleNode('ID').text = ElementName;
objHoldingNode.selectSingleNode('Description').text = ElementDesc;
//next I point to the node where I want the new node to be inserted above and it does pull back a node.
temp = "MasterRecipe[ID='" + RecipeID + "']/RecipeElement/RecipeElement/RecipeElement[ID='" + CurrentNodeID + "']";
var objBatchCurrent = objBatchDoc.selectSingleNode(temp);
//next I want to get the parent of the node above to be used in the insertBefore function.
var temp2 = "MasterRecipe[ID='" + RecipeID + "']/RecipeElement/RecipeElement";
var objBatchCurrentPlusOne;
objBatchCurrentPlusOne = objBatchDoc.selectSingleNode(temp2);
//next I attempt to insert the node. But I get an error "Insert position node must be a child of the node to insert under" on the insertBefore Function. Please help I can't seem to figure what I am doing wrong.
if (objBatchCurrentPlusOne == null) {
}else{
objBatchCurrentPlusOne.insertBefore(objHoldingNode, objBatchCurrent);
}