我正在使用 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"),
执行此代码期间发生异常。
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
如何在元素名称中使用:
字符?
最佳答案
要使用命名空间,您需要先创建命名空间对象:
已更新
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"),
....
关于c# - 如何在 XDocument 元素的名称中使用 ':' 字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6125578/