gss2
gss2

Reputation: 21

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

Upvotes: 2

Views: 68

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1062945

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();

Upvotes: 1

Related Questions