我正在创建名为“stream:stream”的 XElement
对象,但它引发了 XMLException
这样
':' 不能包含在名称中。
这里的第一个流是一个命名空间。
最佳答案
您可以像这样指定命名空间:
XNamespace streamNs = "some-url-here";
// The + operator here creates an XName
XElement element = new XElement(streamNs + "stream");
要创建一个“stream:stream”元素,您需要在某些元素中为 stream
添加一个 xmlns
属性,例如
// Add this to an element - either the element in the namespace, or some parent
// element. The document root is a common place to put all namespaces...
XAttribute streamNs = new XAttribute(XNamespace.Xmlns + "stream",
streamNs.NamespaceName);
关于c# - XElement 中的 XML 解析 ':',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8712667/