xml - Data at the root level is invalid. Line 2, position 12 -


i trying create .xml file in isolatedstorage , updating when try read file getting xmlexception. here code

 using (isolatedstoragefile isostore = isolatedstoragefile.getuserstoreforapplication())         {             xmlwritersettings settings = new xmlwritersettings();                 settings.indent = true;             try             {                 isolatedstoragefilestream isofilestream = isostore.openfile("favourites.xml", filemode.open, fileaccess.readwrite);                 using (xmlwriter writer = xmlwriter.create(isofilestream, settings))                 {                     xdocument doc = xdocument.load(isofilestream);                       doc.root.add(                         new xelement("recipe",                             new xattribute("id", thisrecipe.recipeid),                             new xattribute("title", thisrecipe.title),                             new xattribute("youtubeid", thisrecipe.youtubeid)));                        doc.writeto(writer);                      writer.flush();                   }             }             catch             {                 using (isolatedstoragefilestream isofilestream =                            isostore.openfile("favourites.xml", filemode.create, fileaccess.readwrite))                 {                  using (xmlwriter writer = xmlwriter.create(isofilestream, settings))                     {                         writer.writestartdocument();                          writer.writestartelement("recipes");                         writer.writeendelement();                         writer.writeenddocument();                         writer.flush();                         writer.close();                      }                 }                  using (isolatedstoragefilestream isofilestream =                            isostore.openfile("favourites.xml", filemode.open, fileaccess.readwrite))                      {                       using (xmlwriter writer = xmlwriter.create(isofilestream, settings))                      {                           xdocument doc = xdocument.load(isofilestream);                               doc.root.add(                                 new xelement("recipe",                                     new xattribute("id", thisrecipe.recipeid),                                     new xattribute("title", thisrecipe.title),                                     new xattribute("youtubeid", thisrecipe.youtubeid)));                                 doc.writeto(writer);                             writer.flush();                         }                    }                       }                 } 

and here type xml file trying create , update:

<?xml version="1.0" encoding="utf-8"?>  <recipes>  <recipe id="1" title="dessert" youtubeid="eq1qos__zra" />  <recipe id="2" title="starter" youtubeid="5t2uqokc4nq"/>  <recipe id="3" title="beverages" youtubeid="pqjsuibxtik"/>  </recipes> 


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -