日期:2014-05-18 浏览次数:21240 次
string xmlFilePath1 = Application.StartupPath + @"\x2.xml";
XmlDocument doc = new XmlDocument();
XmlDeclaration Declaration = doc.CreateXmlDeclaration("1.0", "GB2312", "yes");
doc.AppendChild(Declaration);
XmlElement xe = doc.CreateElement("Infos");
doc.AppendChild(xe);
for (int i = 0; i < listview.Items.Count; i++)
{
XmlNode parent = doc.CreateElement("Info" + i.ToString());
ListViewItem temp = listview.Items[i];
for (int j = 0; j < temp.SubItems.Count; j++)
{
string s = temp.SubItems[j].Text;
XmlNode node = doc.CreateElement(listview.Columns[j].Text);
node = doc.CreateTextNode(s);
node.InnerText = s;
parent.AppendChild(node);
}
[color=#FF0000]doc.AppendChild(parent);[/color]这句出现错误
}
doc.Save(xmlFilePath1);