これは私の現在の XML 構造です
<root>
<sublist>
<sub a="test" b="test" c="test"></sub>
</sublist>
</root>
次のC#を使用していますが、実行しようとするとエラーが発生します
public static void writeSub(string a,string b,string c)
{
XDocument xDoc = XDocument.Load(sourceFile);
XElement root = new XElement("sub");
root.Add(new XAttribute("a", a), new XAttribute("b", b),
new XAttribute("c", c));
xDoc.Element("sub").Add(root);
xDoc.Save(sourceFile);
}
どこを間違えますか?
エラーは
nullreferenceexception was unhandled