0

次のようなスタイルの XElement を使用しようとしています。

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

だから私はこれをやっています:

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]">

誰かが私を助けることができますか?

よろしくお願いします

4

1 に答える 1

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);
于 2013-04-04T11:58:50.557 に答える