开发者

Getting values from attributes in xml

Given the following:

<Query>
<Where>
<Eq>
<FieldRef Name=\"ID\" />
<Value Type=\"Title\">
 1 
</Value>
</Eq>
开发者_开发问答</Where>
</Query>

How can I, via using XElement (LINQ to XML):

1) Select the title word (to change it)?

2) Get the 1 value (to change it)?

Thanks


string xml = @"<Query>
<Where>
<Eq>
<FieldRef Name=""ID"" />
<Value Type=""Title"">
 1 
</Value>
</Eq>
</Where>
</Query>";

var el = XElement.Parse(xml);
var value = el.Descendants("Value").FirstOrDefault();
value.Attribute("Type").Value = "abcdef";
value.Value = "ghijkl";

string newXml = el.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜