I have the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<DataTable>
<Columns>
<DataColumn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ColumnName>NomeColuna1</ColumnName>
<TypeName>System.String</TypeName>
</DataColumn>
<DataColumn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ColumnName>NomeColuna2</ColumnName>
<TypeName>System.String</TypeName>
</DataColumn>
<DataColumn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ColumnName>NomeColuna3</ColumnName>
<TypeName>System.Nullable'1[System.Decimal]</TypeName>
</DataColumn>
<DataColumn xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ColumnName>NomeColunaN</ColumnName>
<TypeName>System.Nullable'1[System.Decimal]</TypeName>
</DataColumn>
</Columns>
</DataTable>
Each <DataColumn>
tag was previously generated from an individual serialization process.
At the end, all of these tags are enveloped in the <Columns>
grouping tag during the actual XML write (I use, in this case, a XmlTextWriter
).
As I do not control the serialization of each <DataColumn>
tag, the xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
namespace will be declared for each of them.
Is there a simple way, at the end of the final XML construct, to perform a cleanup to reduce redundancies? The result I hope would be:
<?xml version="1.0" encoding="UTF-8"?>
<DataTable xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Columns>
<DataColumn>
<ColumnName>NomeColuna1</ColumnName>
<TypeName>System.String</TypeName>
</DataColumn>
<DataColumn>
<ColumnName>NomeColuna2</ColumnName>
<TypeName>System.String</TypeName>
</DataColumn>
<DataColumn>
<ColumnName>NomeColuna3</ColumnName>
<TypeName>System.Nullable'1[System.Decimal]</TypeName>
</DataColumn>
<DataColumn>
<ColumnName>NomeColunaN</ColumnName>
<TypeName>System.Nullable'1[System.Decimal]</TypeName>
</DataColumn>
</Columns>
</DataTable>