2012-01-03 52 views
1

我在名称“stream:stream”上创建了XElement对象,但它引发了XMLException,因此 ':'不能包含在名称中。XElement中的XML解析':'

这里第一个流是一个命名空间。

+3

这是一个好主意,通过发布一些代码来展示你已经尝试过的东西。您可能需要创建包含名称空间的XName。 (字符串隐式转换为XNames) – 2012-01-03 13:38:34

+0

嗨rakesh。我怀疑如何创建一个xmpp聊天客户端。这是我的帖子http://stackoverflow.com/questions/9781975/xmpp-chat-c​​lient-in-windows-phone-7-5当你跨越xmpp聊天应用程序的开始阶段,你的答案将是一个很大的帮助我。 – 2012-03-20 11:56:53

回答

5

您指定的命名空间是这样的:

XNamespace streamNs = "some-url-here"; 
// The + operator here creates an XName 
XElement element = new XElement(streamNs + "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);