How can I use the ":" symbol in the name of an XDocument element?

I use XDocument to create the same RSS feed below:

var document = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement("rss", new XElement("channel", new XElement("title", "test"), new XElement("dc:creator", "test"), 

An exception is thrown while executing this code.

The character ':', the hexadecimal value 0x3A, cannot be included in the name.

How to use symbol : in element name?

+8
c # linq special-characters linq-to-xml
source share
1 answer

To use namespaces, you must first create a namespace object:

UPDATED

 XNamespace ns = "http://purl.org/dc/elements/1.1/"; var document = new XDocument( new XDeclaration("1.0", "utf-8", null), new XElement("rss", new XAttribute(XNamespace.Xmlns + "dc", ns) new XElement("channel", new XElement("title", "test"), new XElement(ns + "creator", "test"), .... 
+5
source share

All Articles