c# - An XML document contains error (0,0) -


i have xml document:

<?xml version="1.0" encoding="utf-8" ?> <menu>   <mainmenu>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>   </mainmenu> </menu> 

and whant deserialize list in class mainmenu:

   [serializable()]     public class mainmenu     {         [system.xml.serialization.xmlelementattribute("meal")]         private list<string> meal;          public mainmenu()         {             meal = new list<string>();         }     } 

by method:

private void menudeserializer() {     mainmenu mainmenu = null;     string path = "menuxml.xml";      xmlserializer serializer = new xmlserializer(typeof(mainmenu));      streamreader reader = new streamreader(path);     reader.readtoend();     mainmenu = (mainmenu)serializer.deserialize(reader);     reader.close(); } 

is deserialize meal's list? , if not how this? when i'm trying debug exception: error @ xml file (0,0), (0,0) confusing, problem , how solve it?

1 - remove reader.readtoend(), you're moving stream start when come deserialize tries start end of file.

2 - need remove outer menu element xml, class starts @ mainmenu so should xml...

<?xml version="1.0" encoding="utf-8" ?> <mainmenu>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal>     <meal>example1</meal> </mainmenu> 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -