2012-01-03 49 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);