I have the following code that creates an XML file with order bundle information. And I would like to be able to update the entry in this XML file, instead of deleting everything and adding everything again.
I know I can do this:
xElement.Attribute(attribute).Value = value;
But this will change every attribute with the same name as the attribute. How can I change the value of something only when the record identifier is "jason", for example? Do I need to upload an XML file, iterate over the entire file until it finds a match for the attribute that I want to change, then change it and then save the file again?
Any help / suggestions are appreciated.
thanks
This is what my XML file looks like:
XElement xElement; xElement = new XElement("Orders"); XElement element = new XElement( "Order", new XAttribute("Id", CustomId), new XAttribute("Quantity", Quantity), new XAttribute("PartNo", PartNo), new XAttribute("Description", Description), new XAttribute("Discount", Discount), new XAttribute("Freight", Freight), new XAttribute("UnitValue", UnitValue), new XAttribute("LineTotal", LineTotal) ); xElement.Add(element); xElement.Save(PartNo + ".xml"); <?xml version="1.0" encoding="utf-8"?> <Orders> <Order Id="V45Y7B458B" Quantity="2" PartNo="5VNB98" Description="New Custom Item Description" Discount="2.00" Freight="2.90" UnitValue="27.88" LineTotal="25.09" /> <Order Id="jason" Quantity="2" PartNo="jason" Description="New Custom Item Description" Discount="2.00" Freight="2.90" UnitValue="27.88" LineTotal="25.09" /> </Orders>
source share