I have add one xml file in Assets folder This is Empty and when i try to add list data in xml file this return a error. error show in images please check the image . here i have attach a image . Please Help me This is my code
public void BookmarkPage()
{
List<Bookmarkdata> data = new List<Bookmarkdata>();
data.Add(new Bookmarkdata() { Bookname = "Kate", Bookid = "Brown", BookPath = "Brown", Pageno = 25 });
data.Add(new Bookmarkdata() { Bookname = "Tom", Bookid = "Stone", BookPath = "Brown", Pageno = 63 });
data.Add(new Bookmarkdata() { Bookname = "Michael", Bookid = "Liberty", BookPath = "Brown", Pageno = 37 });
AddXml(data);
}
private void AddXml(List<Bookmarkdata> data)
{
XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
xmlWriterSettings.Indent = true;
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile("BookmarkFile.xml", FileMode.Create))
{
XmlSerializer serializer = new XmlSerializer(typeof(List<Bookmarkdata>));
using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSettings))
{
serializer.Serialize(xmlWriter, data);
}
}
}
This is my class
class Bookmarkdata
{
string bookname;
string bookid;
string bookPath;
int pageno;
public string Bookname
{
get { return bookname; }
set { bookname = value; }
}
public string Bookid
{
get { return bookid; }
set { bookid = value; }
}
public string BookPath
{
get { return bookPath; }
set { bookPath = value; }
}
public int Pageno
{
get { return pageno; }
set { pageno = value; }
}
}
}
Here i attach a error image in visual studio
As the error message suggested, Bookmarkdata
class is inaccessible due to it's protection level. You need to simply set it's access modifier to public :
public class Bookmarkdata
{
.........
.........
}
and XmlSerializer
will be able to serialize your list smoothly :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.