我想向我的所有 XML 文件添加一个 Test(通用)属性。这样当我想测试它们时我可以将它用作公共属性。
我尝试了 CreateAttribute 但 Linq 无法识别它
我尝试了“xElement.Add(new XAttribute("Test", value));”但也没用
有什么建议么?
Thanks
例如这里是一个代码
public void updateXmlFile(string strFileName)
{
XDocument oXDoc = XDocument.Load(strFileName);
XElement oDcElement = oXDoc.Root.FirstNode as XElement;
//Generate a Unique String to replace the original attribute value
string newValue = GetUniqueKey();
//oDcElement.Add(new XAttribute("Test", newValue)); /*NullReferenceException*/
oDcElement.Attribute("Remark").Value = newValue; //This changes only the Remark Attribute
oXDoc.Save(strFileName); //which isn't available in all XMLs
}
我想向通过此方法传递的 XML 添加一个附加的通用值,并为其指定一个随机值
我的目标是能够对 XML 进行更改,然后将其与另一个文件夹中的原始副本进行比较
使用设置属性:
oDcElement.SetAttributeValue("Test", newValue);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)