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


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);
        txtXml.Text = doc.ToString(SaveOptions.DisableFormatting);

    private void ProcessElement(XElement element)
        if (element.HasElements)
            element.Elements().ToList().ForEach(e => ProcessElement(e));
            element.Value = element.Value.ToUpper();

Related Articles