Thursday, April 12, 2018

Removing Namespaces from and XDocument

    private XDocument RemoveNamespace(XDocument xdoc)
    {
        foreach (XElement e in xdoc.Root.Descendants())
        {
            if (e.Name.Namespace != XNamespace.None)
            {
                e.Name = XNamespace.None.GetName(e.Name.LocalName);
            }
            if (e.Attributes().Any(a => a.IsNamespaceDeclaration || a.Name.Namespace != XNamespace.None))
            {
                e.ReplaceAttributes(e.Attributes().Select(a => a.IsNamespaceDeclaration ? null : a.Name.Namespace != XNamespace.None ? new XAttribute(XNamespace.None.GetName(a.Name.LocalName), a.Value) : a));
            }
        }
        return xdoc;
    }

Encrypt/Decrypt the App.Config

Program.cs using System; using System.Diagnostics; using System.IO; namespace EncryptAppConfig {     internal class Program     {         pr...