Question
I have a XML schema as this which i need to append more product to this file , i was trying XMLdocument and Xdocument both classes but didnt got any good results
<prodcuts>
<product>
<name>123</name>
<price>123</price>
</product>
</products>
CODE:
i was trying Xdocument class with this code
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");
Exception
Value cannot be null.
Parameter name: other
I was tring XMLdocument class too but no results…
Where am i wrong ? … is this problem can solved in LINQ or any other method ?
This will create a new XElement under the Root node which is where I think you want it.