Remove XNamespace in XElement c #

1

I need to remove the XNamespace that comes as default on an rss return. Here is the code below:

 static void Main(string[] args)
    {

        XNamespace ns = "http://search.yahoo.com/mrss";

         var item = new XElement(ns + "content",
         new XAttribute(XNamespace.Xmlns + "media", ns),
         new XAttribute("duration", "512"),
         new XAttribute("type", "video/mp4"),
         new XAttribute("url", "http://tv-download.dw.de/dwtv_video/flv/gle/gle20140609_ghana_sd_sor.mp4"),
         new XElement(ns + "thumbnail", new XAttribute(XNamespace.Xmlns + "media", ns),
         new XAttribute("url", "http://www.dw.de/image/0,,17611287_403,00.jpg"),
         new XAttribute("type", "image/jpeg"),
         new XAttribute("height", "480"),
         new XAttribute("width", "853")),
         new XElement(ns + "title",
         new XAttribute(XNamespace.Xmlns + "media", ns), "Video caption"),
         new XElement(ns + "description",
         new XAttribute(XNamespace.Xmlns + "media", ns), "description"),
         new XElement(ns + "copyright",
         new XAttribute(XNamespace.Xmlns + "media", ns), "Francisco Cunha, 2014"));


        Console.WriteLine(item);
        Console.ReadLine();
    }
    
asked by anonymous 28.07.2014 / 21:54

1 answer

1

This is because you are forcing the name of namespace to media :

new XAttribute(XNamespace.Xmlns + "media", ns),

Switch to:

new XAttribute(XNamespace.Xmlns, ns),

This should generate the following root element:

<content xmlns="http://search.yahoo.com/mrss">
...
</content>

The other elements should also have "media" removed, so that tags are generated without the name of namespace .

    
28.07.2014 / 23:21