// Delete the specified security element if the current time is past // the time stored in the destroytime tag. private static SecurityElement DestroyTree(SecurityElement xmlElement) { SecurityElement localXmlElement = xmlElement; SecurityElement destroyElement = localXmlElement.SearchForChildByTag("destroytime"); // Verify that a destroytime tag exists. //<Snippet17> if (localXmlElement.SearchForChildByTag("destroytime") != null) //</Snippet17> { // Retrieve the destroytime text to get the time // the tree can be destroyed. //<Snippet18> string storedDestroyTime = localXmlElement.SearchForTextOfTag("destroytime"); //</Snippet18> DateTime destroyTime = DateTime.Parse(storedDestroyTime); if (DateTime.Now > destroyTime) { localXmlElement = null; Console.WriteLine("The XML security tree has been deleted."); } } // Verify that xmlElement is of type SecurityElement. //<Snippet21> if (xmlElement.GetType().Equals( typeof(System.Security.SecurityElement))) //</Snippet21> { // Determine whether the localXmlElement object // differs from xmlElement. //<Snippet20> if (xmlElement.Equals(localXmlElement)) //</Snippet20> { // Verify that the tags, attributes and children of the // two security elements are identical. //<Snippet22> if (xmlElement.Equal(localXmlElement)) //</Snippet22> { // Return the original security element. return(xmlElement); } } } // Return the modified security element. return(localXmlElement); }