我需要在我的 SQL Server 数据库中的同一列中存储许多记录,为此我使用 XML 字段。在后端,我有读取/写入 xml 记录并将数据插入表中的代码。该表是可变大小。我在从表中读取字段并将它们插入 xml 变量时遇到问题。 我需要得到的是:
<BigTag>
<SmallTagName1> something</SmallTagName1>
<SmallTagName2> thanksForanswering</SmallTagName2>
<SmallTagName3> youareawesome</SmallTagName3>
</BigTag>
表格是:
smalltagTable[] = {something,thanksForanswering,youareawesome,....}
这是我的代码:
XElement WidgetListE1 = null;
WidgetListE1 = new XElement("BigTag" );
string smalltagname = "smalltag ";
string smalltagdata;
for(int i=0;i<smalltagTable.Length; i++ )
{
SmallTagname = "smallTagName " + i;
smalltagdata = smalltagTable[i];
WidgetListE1.Add(new XElement(smallTagName.ToString(),SmalltagData.ToString() ));
}
string a2 = WidgetListE1.ToString();
问题是这段代码遇到了错误:
“”字符,十六进制值 0x20,不能包含在名称中。 在线:
WidgetListE1.Add(new XElement(smallTagName.ToString(),SmalltagData.ToString() ));
最佳答案
我发布这个只是为了确保答案清楚地出现。致谢 Panagiotis Kanavos。问题是 xml 的标记中有一个空格。而不是:
<smalltag 1> something </smalltag 1>
应该是
<smalltag1> something</smalltag1>
关于c# - 表到 xml 记录 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35577506/