Remove All XML Namespaces - CSharp System.Xml

CSharp examples for System.Xml:XML Namespace

Description

Remove All XML Namespaces

Demo Code


using System.Xml.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Text;
using System.Linq;
using System.IO;/*from ww w.  j a va 2s  .c om*/
using System.Collections.Generic;
using System;

public class Main{
        private static XElement RemoveAllNamespaces(XElement xmlDocument)
        {
            if (!xmlDocument.HasElements)
            {
                var xElement = new XElement(xmlDocument.Name.LocalName) {Value = xmlDocument.Value};
                return xElement;
            }
            return new XElement(xmlDocument.Name.LocalName, xmlDocument.Elements().Select(el => RemoveAllNamespaces(el)));
        }
}

Related Tutorials