我知道關於http://msdn.microsoft.com/en-us/library/bb387069.aspx。我已閱讀示例文章。但在F#中,String向XName轉換有一些麻煩。一些代碼,我嘗試使用:如何向XElement添加名稱空間前綴
let (!!) : string -> XName = XName.op_Implicit
> XElement(!!"tmp:" + !!"root", !!"Content");;
stdin(9,21): error FS0001: The type 'XName' does not support any operators named '+'
> XElement(!!("tmp:" + "root"), !!"Content");;
System.Xml.XmlException: The ':' character, hexadecimal value 0x3A, cannot be included in a name.
> XElement("tmp" + "root", "Content");;
The type 'string' is not compatible with the type 'XName'
我想要什麼:
<tmp:root>Content</tmp:root>
UPD: 我只想前綴命名空間標記之前,這樣的:
<tmp:root>Content</tmp:root>
無類似的東西:
> let ns = XNamespace.Get "http://tmp.com/";;
val ns : XNamespace = http://tmp.com/
> let xe = XElement(ns + "root", "Content");;
val xe : XElement = <root xmlns="http://tmp.com/">Content</root>
好吧,「讓urlset = new XElement(ns +」blank「,」...因爲我不需要一個空白節點) – psct