function setNodeValue(xpath, value) { var xmlNode = getNode(xpath); if (!xmlNode) return; // The xsi:nil needs to be removed before we set the value. if (value !=""&& xmlNode.getAttribute("xsi:nil")) xmlNode.removeAttribute("xsi:nil"); // Setting the value would mark the document as dirty. // Let's do that if the value has really changed. if (xmlNode.text != value) xmlNode.text = value; } function getNode(xpath) { // Both XML node and absolute XPath are allowed. if (typeof(xpath) =="string") return XDocument.DOM.selectSingleNode(xpath); else return xpath; }