我怎么可以用':'字符的XDocument元素的名称? [英] How can I use ':' character in a name of XDocument element?
本文介绍了我怎么可以用':'字符的XDocument元素的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的XDocument创建下同code一个RSS:
I'm using XDocument to create a RSS same below code:
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"),
这是例外,这code中的执行过程中发生的。
An exception occurring during the execution of this code.
的':'字符,十六进制值0x3A的不能被包含在一个名称
The ':' character, hexadecimal value 0x3A, cannot be included in a name.
我如何使用:
字符元素的名称
How can I use :
character in a name of element?
推荐答案
要使用的命名空间,你需要首先创建命名空间对象:
To use namespaces, you'll need to create the namespace object first:
更新时间:
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"),
....
这篇关于我怎么可以用':'字符的XDocument元素的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文