До сих пор я писал в XML, хранящий список и некоторые другие ценные сведения через пропускание его через конструктор и сохранение его в качестве так:Список в XML затем Чтение XML
RoundEdit._quizStruct.Add(new RoundEdit(quizId, roundId, roundName, QuestionsCount, Questions));
Это конструктор и что не.
public RoundEdit()
{
quizStruct = new List<RoundEdit>();
}
public RoundEdit(int inQuizID, int inRoundId,string inRoundName, int inNumOfQuestions, List<int> inRoundQuestions)
{
QuizId = inQuizID;
RoundId = inRoundId;
roundName = inRoundName;
numOfQuestions = inNumOfQuestions;
roundQuestions = inRoundQuestions;
}
public static void saveRounds()
{
SaveXmlQuiz.SaveData(_quizStruct, "rounds.xml");
}
Это xml-файл, который я пытаюсь прочитать и сериализую.
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfRoundEdit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RoundEdit>
<_quizId>0</_quizId>
<_roundId>1</_roundId>
<_roundName>1</_roundName>
<_numOfQuestions>2</_numOfQuestions>
<_roundQuestions>
<int>2</int>
<int>3</int>
</_roundQuestions>
</RoundEdit>
<RoundEdit>
<_quizId>0</_quizId>
<_roundId>2</_roundId>
<_roundName>2</_roundName>
<_numOfQuestions>2</_numOfQuestions>
<_roundQuestions>
<int>2</int>
<int>3</int>
</_roundQuestions>
</RoundEdit>
</ArrayOfRoundEdit>
но когда я использую этот метод
XmlSerializer xs; FileStream read; RoundEdit info;
xs = new XmlSerializer(typeof(RoundEdit));
read = new FileStream("rounds.xml", FileMode.Open, FileAccess.Read, FileShare.Read);
try
{
info = (RoundEdit)xs.Deserialize(read);//exception here for john to look at
RoundList.Add(new RoundEdit(info._quizId, info._roundId, info._roundName, info._numOfQuestions, info._roundQuestions));
}
Я получаю сообщение об ошибке из Существует ошибка в документе XML (2, 2), я думаю, что это причина того, как он читает в список, который хранился в roundQuestions, но я не уверен, может ли кто-нибудь помочь?