Я пытаюсь создать следующий XML-документ:
FileStream fs = new FileStream(path, FileMode.Create);
XmlWriter w = XmlWriter.Create(fs);
w.WriteStartDocument();
w.WriteStartElement("People");
w.WriteStartElement("Person");
// loop over checked elements
foreach (var xxx in checkedListBox1.Items)
{
w.WriteAttributeString("Name", textBox1.Text);
w.WriteAttributeString("GamerTag", textBox2.Text);
w.WriteAttributeString("Wins", textBox3.Text);
w.WriteAttributeString("Losses", textBox4.Text);
w.WriteAttributeString("Ratio", textBox5.Text);
// get id of this match
id = checkedListBox1.Text.Substring(1, 3);
// call the function at the service to download the type of struct we require
res = client.photo(id);
format = System.Drawing.Imaging.ImageFormat.Jpeg;
w.WriteElementString("Picture-id", res.ToString());
if (checkedListBox1.GetItemChecked(checkedListBox1.SelectedIndex))
{
// do something
w.WriteElementString("Game", checkedListBox1.Text);
}
w.WriteEndElement();
}
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
fs.Close();
Однако при отладке я получаю эту ошибку -
Токен StartAttribute в состоянии Element Content приведет к созданию недопустимого XML-документа.
На линии - w.WriteAttributeString("Name", textBox1.Text);
Я проверил наличие пробелов и т. д., однако не уверен, почему это происходит, любая помощь приветствуется.
using
на своемFileStream
, чтобы обеспечить расположение. - person Jesse C. Slicer   schedule 28.11.2011