在C#中使用linq to xml创建动态xml文件错误“字符串长度不能为零。参数名称:oldValue”

时间:2012-12-03 03:58:40

标签: c# xml linq-to-xml

以下是错误的屏幕截图

enter image description here

enter image description here enter image description here

我想要的是动态创建一个xml文件,xml的节点将是string[] textBoxNamesArray,值将是string[] textBoxTextArray

如何解决此问题?

2 个答案:

答案 0 :(得分:2)

你要替换空字符串,你i.replace()的第一个参数是"",不允许

你必须在这里提到你想要替换的旧字符串

如果你不想替换任何值,那么就这样做:

xml.Add(new XElement(i, o));

答案 1 :(得分:2)

问题在于对String.Replace的调用。 The first argument cannot be an empty string。而且,由于您正在用string.Empty替换“”,因此该呼叫并非真正需要且可以删除。

因此将行更改为

xml.Add(new XElement(i, o));