问题
我有一个 XML 模式,我需要将更多产品附加到这个文件中,我正在尝试两个类XMLdocument
,Xdocument
但没有得到任何好的结果
<prodcuts>
<product>
<name>123</name>
<price>123</price>
</product>
</products>
代码:
我正在使用此代码尝试 Xdocument 类
XDocument xmldoc = XDocument.Load("F://products.xml");
XElement parentElement = new XElement(xmldoc.XPathSelectElement("product"));
XElement newElement = new XElement("name","32323");
XElement newElement = new XElement("price","150");
parentElement.Add(newElement);
xmldoc.Save("F://products.xml");
例外
Value cannot be null.
Parameter name: other
我也在XMLdocument
上课,但没有结果...
我哪里错了?...这个问题可以通过LINQ
或任何其他方法解决吗?