c# - 去除XML中的namespace


static string RemoveNamespaces(string xml)
        {
            var xmlDoc = XElement.Parse(xml);
            xmlDoc = stripNS(xmlDoc);
            return xmlDoc.ToString();
        }

        static XElement stripNS(XElement root)
        {
            return new XElement(
                root.Name.LocalName,
                root.HasElements ?
                root.Elements().Select(el => stripNS(el)) :
                (object)root.Value
            );
        }

你可能感兴趣的:(C#)