SyndicationItem.ElementExtensions Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the element extensions contained in the syndication item.

Namespace:   System.ServiceModel.Syndication
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

public SyndicationElementExtensionCollection ElementExtensions { get; }

Element extensions are valid XML elements that are not specified in either the Atom 1.0 or RSS 2.0 specifications. Any valid XML element can be added as an extension provided its namespace is different from the enclosing namespace. When serialized, extensions are written like any other XML element.

<mg:MyElement xmlns:mg="http://myserver/elements" />

For a complete example that shows how to add element extensions, see the Loosely-Typed Extensions Sample sample.

The following code shows how to add element extensions to a SyndicationItem instance.

SyndicationItem item = new SyndicationItem();

// Add several different types of element extensions
item.ElementExtensions.Add("simpleString", "", "hello, world!");
item.ElementExtensions.Add("simpleString", "", "another simple string");

// DataContractExtension is a user-defined type marked with the DataContractAttribute
item.ElementExtensions.Add(new DataContractExtension() { Key = "X", Value = 4 });

// XmlSerializerExtension is a user-defined type that defines a ToString() method
item.ElementExtensions.Add(new XmlSerializerExtension() { Key = "Y", Value = 8 }, new XmlSerializer(typeof(XmlSerializerExtension)));

item.ElementExtensions.Add(new XElement("xElementExtension", new XElement("Key", new XAttribute("attr1", "someValue"), "Z"),
    new XElement("Value", new XAttribute("attr1", "someValue"), "15")).CreateReader());

.NET Framework
Available since 3.5
Available since 2.0
Return to top