如何在XDocument元素的名称中使用’:’字符?
我正在使用XDocument在代码下面创建一个RSS:
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"),
执行此代码期间发生的exception。
‘:’字符,hex值0x3A,不能包含在名称中。
我如何使用:
元素名称中的字符?
要使用名称空间,首先需要创建名称空间对象:
更新
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"), ....