table to xml record c#
<p>I need to store on my SQL Server DB many records in the same column and I use XML field for this.On the backend I have code that reads/writes the xml records and inserts the data in a table.The table is of variable size. I have problem in reading the fields from the table and insert them into an xml variable.
What I need to get is :</p>

<pre><code>&lt;BigTag&gt;
&lt;SmallTagName1&gt;  something&lt;/SmallTagName1&gt;
&lt;SmallTagName2&gt;  thanksForanswering&lt;/SmallTagName2&gt;
&lt;SmallTagName3&gt;  youareawesome&lt;/SmallTagName3&gt;
&lt;/BigTag&gt;
</code></pre>

<p>The table is:</p>

<pre><code>smalltagTable[] = {something,thanksForanswering,youareawesome,....}
</code></pre>

<p>here is my code:</p>

<pre><code>XElement WidgetListE1 = null;

WidgetListE1 = new XElement("BigTag"  );

string smalltagname = "smalltag ";
string smalltagdata;

for(int i=0;i&lt;smalltagTable.Length; i++ )
{
    SmallTagname = "smallTagName " + i;
    smalltagdata = smalltagTable[i];
    WidgetListE1.Add(new XElement(smallTagName.ToString(),SmalltagData.ToString() ));
}

string a2 = WidgetListE1.ToString();
</code></pre>

<p>The problem is that this code hits the error :</p>

<p>The ' ' character, hexadecimal value 0x20, cannot be included in a name.
on the line :</p>

<pre><code>WidgetListE1.Add(new XElement(smallTagName.ToString(),SmalltagData.ToString() ));
</code></pre>