开发者

Getting values from attributes in xml

开发者 https://www.devze.com 2023-02-19 11:25 出处:网络
Given the following: <Query> <Where> <Eq> <FieldRef Name=\\\"ID\\\" /> <Value Type=\\\"Title\\\">

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

精彩评论

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