// // public static methods // // replaces the inputElement with the provided EncryptedData public static void ReplaceElement(XmlElement inputElement, EncryptedData encryptedData, bool content) { if (inputElement == null) { throw new ArgumentNullException("inputElement"); } if (encryptedData == null) { throw new ArgumentNullException("encryptedData"); } // First, get the XML representation of the EncryptedData object XmlElement elemED = encryptedData.GetXml(inputElement.OwnerDocument); switch (content) { case true: // remove all children of the input element Utils.RemoveAllChildren(inputElement); // then append the encrypted data as a child of the input element inputElement.AppendChild(elemED); break; case false: XmlNode parentNode = inputElement.ParentNode; // remove the input element from the containing document parentNode.ReplaceChild(elemED, inputElement); break; } }