score:2
Accepted answer
LINQ expressions shouldn't normally modify the value of the source. They should only return new values (think them as a filter... You put something in, something different comes out)
foreach (var desc in doc.Descendants()) {
var nodes = desc.Nodes().Where(p => p.NodeType == XmlNodeType.Text);
foreach (XText node in nodes) {
node.Value = node.Value.ToUpper();
}
}
score:1
I solved it this way - not sure its the best but it works.
private void btnConvert_Click(object sender, EventArgs e)
{
XDocument doc = XDocument.Parse(txtXml.Text);
ProcessElement(doc.Elements().First());
txtXml.Text = doc.ToString(SaveOptions.DisableFormatting);
}
private void ProcessElement(XElement element)
{
if (element.HasElements)
element.Elements().ToList().ForEach(e => ProcessElement(e));
else
element.Value = element.Value.ToUpper();
}
Source: stackoverflow.com
Related Articles
- UpperCase all Xml element values with LINQ
- How to best extract attribute values and element values with LINQ and C#
- Linq to XML: create an anonymous object with element attributes and values
- Select only the lowest values with Linq
- Preserve order of values with linq and ToLookup()
- Linq to update a collection with values from another collection?
- LINQ Order By Descending with Null Values on Bottom
- Using Linq to do a Contains with multiple values
- get last element with linq to sql
- linq how to select a parent with a child collection that contains one or many of an array (or list) of values
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- Sum nested values with Linq
- How to update an element with a List using LINQ and C#
- Stored Procedure return values with linq data context
- How do I use Linq ToDictionary to return a dictionary with multiple values in the dictionary items?
- How can I iterate over a collection and change values with LINQ extension methods?
- Get grouped comma separated values with linq
- LINQ question ... need to get element with min value
- Checking if a XML child element exists with Linq to XML
- Full object projection with additional values in LINQ
- C# LINQ Select objects with the same value of one property join values of other
- Linq query with subquery as comma-separated values
- Linq to Dictionary<string, List<string>> with Null values
- Using LINQ to delete an element from a ObservableCollection Source
- LINQ: Get element with highest of two/multiple values
- Linq deferred execution with local values
- Uppercase a List of object with LINQ
- LINQ Source Code Available
- C# Create object with dynamic properties : LINQ select List<object> values by property names array
- Ordering Distinct values with LINQ
- Getting an array of dates (yearly and absolute)
- C# Linq full outer join on repetitive values
- Error with converting int to string in Linq to entities
- How to pull a SQL Server table into memory in order to run queries against it
- EF can't get the reference entity of navigation property of an entity
- Linq: adding conditions to the where clause conditionally
- How can I write my SQL query in LINQ?
- Is there an Online version of LINQ Pad?
- Use LINQ to get length of dimensions of Array
- Speeding up my BOM calculation
- LINQ / VB.NET select distinct from dataset
- How to get the index of element inside nested Lists
- Linq SQL query has more precision for doubles
- Editing 2 tables in one view
- Selecting Multiple Nodes on the Same Level w/ LINQ
- Mapping A Property Of List<T> Using Automapper
- MVC SqlQuery and a 2nd sort
- How to query a datable with dynamic columns
- Filter a Generic list using LINQ using a PropertyName as a string literal - Using dynamics
- Using linq query on ObservableCollection of interface?