How to remove all namespaces from XML with C#?

前端 未结 30 2525
悲哀的现实
悲哀的现实 2020-11-22 13:30

I am looking for the clean, elegant and smart solution to remove namespacees from all XML elements? How would function to do that look like?

Defined interface:

30条回答
  •  青春惊慌失措
    2020-11-22 13:37

    Here is my VB.NET version of Dexter Legaspi C# Version

    Shared Function RemoveAllNamespaces(ByVal e As XElement) As XElement
            Return New XElement(e.Name.LocalName, New Object() {(From n In e.Nodes Select If(TypeOf n Is XElement, RemoveAllNamespaces(TryCast(n, XElement)), n)), If(e.HasAttributes, (From a In e.Attributes Select a), Nothing)})
    End Function
    

提交回复
热议问题