﻿//Fonction de vidange d'un contenu d'un noeud
function cleanTags(idTag) {
  var destroyNode = document.getElementById(idTag)
  while(destroyNode.hasChildNodes()) {
    destroyNode.removeChild(destroyNode.firstChild);
  }
}

function clearNode(node) {
  while(node.hasChildNodes()) {
    node.removeChild(node.firstChild);
  }
}

//Fonctions de traitement des noeuds XML
function testChildNode(node) {
  if(node.firstChild) {
    return document.createTextNode(node.firstChild.nodeValue);
  }
  else {
    return document.createTextNode("AUCUN");
  }
}

function xpathNodeList(expression,node,doc) {
  var isIE = false;
  var nodes = new Array();
	
  if(window.ActiveXObject) {
    isIE = true;
  }
  
  if (isIE) {
    var nodeList = node.selectNodes(expression);
    for(u=0;u<nodeList.length;u++) {
    	nodes[u] = nodeList.item(u);
    }
  }
  else {
    var xpathresult = doc.evaluate(expression, node, null, 6, null);
    for(u=0;u<xpathresult.snapshotLength;u++) {
      nodes[u] = xpathresult.snapshotItem(u);
    }
  }
  return nodes;
}

function AddNodes(insertExpression,node,bool) {
  var copyNode;
  
  if (window.ActiveXObject) {
    copyNode = node.cloneNode(bool);
  }
  else {
    copyNode = XMLcache.importNode(node,bool);
  }
  
  var nodeList = xpathNodeList(insertExpression,XMLcache,XMLcache);
  nodeList[0].appendChild(copyNode);
}

function createNode(insertExpression,xmlNode,document) {
  var nodeList = xpathNodeList(insertExpression,document,document)
  var node = document.createElement(xmlNode);
  nodeList[0].appendChild(node);
}

function getChildData(parentEl) {
  if (parentEl == null) {
    return null;
  }
  var tempNode = parentEl.firstChild;
  var text="";
  
  while (tempNode != null) {
    switch (tempNode.nodeType) {
      case 3 /*TEXT_NODE*/ :
        text+=tempNode.nodeValue;
      break;

      case 4 /*CDATA_SECTION_NODE*/ :
        text+=tempNode.nodeValue;
      break;
      
      default :
      break;
    }
    tempNode = tempNode.nextSibling;
  }
  return text;
}
