using System.Collections.Generic;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
public static void Test()
var xdocument = XDocument.Parse(GetXml());
var tableName = XmlConvert.EncodeLocalName("dgvViewAll_Vertical");
var sectionName = XmlConvert.EncodeLocalName("Section ");
var groupKeyName = XmlConvert.EncodeLocalName("GroupKey");
var columnName = XmlConvert.EncodeLocalName("2010 FYA");
var columnValue = "New Value";
var ns = xdocument.Root.Name.Namespace;
var columns = xdocument.Root
.Elements(ns + tableName)
.Where(e => e.Element(ns + sectionName)?.Value == e.Element(ns + groupKeyName).Value.Split('~').Last())
.Select(e => e.Element(ns + columnName));
foreach (var column in columns)
column.Value = columnValue;
Console.WriteLine(xdocument);
Assert.IsTrue(xdocument.ToString().Contains(@"<_x0032_010_x0020_FYA>New Value</_x0032_010_x0020_FYA>"));
static string GetXml() => @"<?xml version=""1.0"" standalone=""yes""?>
<Section_x0020_>MS</Section_x0020_>
<LineItem>Morgan Stanley</LineItem>
<Revise_x0020_Date>10-09-2020</Revise_x0020_Date>
<_x0032_010_x0020_FYA>126,966.0000</_x0032_010_x0020_FYA>
<_x0032_011_x0020_FYA>128,810.0000</_x0032_011_x0020_FYA>
<_x0032_012_x0020_FYA>140,948.0000</_x0032_012_x0020_FYA>
<_x0032_013_x0020_FYA>150,090.0000</_x0032_013_x0020_FYA>
<_x0031_Q_x0020_2014A>37,524.0000</_x0031_Q_x0020_2014A>
<_x0032_Q_x0020_2014A>44,181.0000</_x0032_Q_x0020_2014A>
<_x0033_Q_x0020_2014A>45,259.0000</_x0033_Q_x0020_2014A>
<_x0034_Q_x0020_2014A>49,656.0000</_x0034_Q_x0020_2014A>
<_x0032_014_x0020_FYA>176,620.0000</_x0032_014_x0020_FYA>
<_x0031_Q_x0020_2015A>46,791.0000</_x0031_Q_x0020_2015A>
<_x0032_Q_x0020_2015A>53,233.0000</_x0032_Q_x0020_2015A>
<_x0033_Q_x0020_2015A>53,420.0000</_x0033_Q_x0020_2015A>
<_x0034_Q_x0020_2015A>56,477.0000</_x0034_Q_x0020_2015A>
<_x0032_015_x0020_FYA>209,921.0000</_x0032_015_x0020_FYA>
<_x0031_Q_x0020_2016A>50,624.0000</_x0031_Q_x0020_2016A>
<_x0032_Q_x0020_2016A>54,341.0000</_x0032_Q_x0020_2016A>
<_x0033_Q_x0020_2016A>56,802.0000</_x0033_Q_x0020_2016A>
<GroupKey>Consensus Model~Total Revenue Including VAT~RD_001~NBM~~1~MS</GroupKey>
public static void Main()
Console.WriteLine("Environment version: {0} ({1})", System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription , GetNetCoreVersion());
Console.WriteLine("Failed with unhandled exception: ");
public static string GetNetCoreVersion()
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
var assemblyPath = assembly.Location.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries);
int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App");
if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2)
return assemblyPath[netCoreAppIndex + 1];