XElement中的XML解析':'

rak*_*esh 1 c# xml xmpp namespaces windows-phone-7

XElement在名称"stream:stream"上创建对象,但它引发XMLException了':'不能包含在名称中.

这里的第一个流是命名空间.

Jon*_*eet 5

您可以指定以下命名空间:

XNamespace streamNs = "some-url-here";
// The + operator here creates an XName
XElement element = new XElement(streamNs + "stream");
Run Code Online (Sandbox Code Playgroud)

要使其创建"stream:stream"元素,您需要在某个元素中使用xmlns属性stream,例如

// 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);
Run Code Online (Sandbox Code Playgroud)