2013-04-04 51 views
0

我試着去與風格類似的XElement:的XElement增添風采

<g style="fill-opacity:0.7"> 

這樣的IM這樣做:

XElement root = new XElement("g"); 
root.SetAttributeValue("style", 
       from attributes in Child.Attributes 
       where char.IsUpper(attributes.Key[0]) & !attributes.Value.ToString().StartsWith(transformNS) 
       select new XAttribute("style", attributes.Key + ":" + attributes.Value)); 

,但我已經是

<g style="System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Collections.Generic.KeyValuePair`2[System.String,System.Object],System.Xml.Linq.XAttribute]"> 

有人能夠幫助我?

問候

+0

你們是不是要選擇一個子屬性? – 2013-04-04 11:55:00

+0

可能會超過一個 – user1977936 2013-04-04 11:56:19

+0

那麼你想如何結合它們?您的代碼不包含任何要做的事情。 – 2013-04-04 11:57:03

回答

0

那是因爲你的選擇是一個完整的XAttribute作爲一個屬性的值。 您需要迭代您的屬性並將它們集中到一個字符串中。然後使用此字符串作爲您的屬性的值。

事情是這樣的:

XElement root = new XElement("g"); 
IEnumerable<string> styleprops = from attributes in Child.Attributes 
           where char.IsUpper(attributes.Key[0]) & !attributes.Value.ToString().StartsWith(transformNS) 
           select attributes.Key + ":" + attributes.Value 

string value = string.empty; 

foreach(string prop in styleprops){ 
    value += prop + ";"; 
} 

root.SetAttributeValue("style", value); 
+0

謝謝你,那就解決吧 – user1977936 2013-04-04 12:01:40

+0

好的,很樂意幫忙。 (如果能解決您的問題,請將答覆標記爲答案) – Kenneth 2013-04-04 12:04:07