Why the XML Element is not appended at the end of the file

masterrr

New Member
I'm trying to add an Element to an XML file in the IsolatedStorage, but instead of adding it at the of the root, the file is duplicated and added at the end :\[code\]<?xml version="1.0" encoding="utf-8"?><root> <lampe id="1" nom="lampe1" content="Tables" header="Lampes de la cuisine" adresse="A1" /> <lampe id="2" nom="lampe2" content="Porte et garage" header="Lampe du jardin" adresse="C3" /></root><?xml version="1.0" encoding="utf-8"?><root> <lampe id="1" nom="lampe1" content="Tables" header="Lampes de la cuisine" adresse="A1" /> <lampe id="2" nom="lampe2" content="Porte et garage" header="Lampe du jardin" adresse="C3" /> <child attr="1">data1</child></root>\[/code\]This is the code I'm using :\[code\]_xdoc = new XDocument();using (var store = IsolatedStorageFile.GetUserStoreForApplication()){ using (IsolatedStorageFileStream isoStore = new IsolatedStorageFileStream("lampes.xml", FileMode.Open, store)) { _xdoc = XDocument.Load(isoStore); int nextNumber = _xdoc.Element("root").Elements("lampe").Count() + 1; XElement newChild = new XElement("lampe", "data" + nextNumber); newChild.Add(new XAttribute("attr", nextNumber)); _xdoc.Element("root").Add(newChild); _xdoc.Save(isoStore); }}\[/code\]What I'm missing here ?
 
Back
Top