private bool save2 saving via xml if textBox1 Text String Empty textBo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
private bool save2()
{
//saving via xml
if (textBox1.Text == String.Empty || textBox2.Text == String.Empty)
return false;
XDocument doc =
new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XComment("Database of frames and rules"),
new XElement("Database",
new XElement("About", new XElement("Title", textBox1.Text), new XElement("Company", textBox2.Text)),
new XElement("Frames"),
new XElement("Rules")));
doc.Save("our.xml");
XElement frameElemt = new XElement("Frame", new XAttribute("ID", 1));
//пример добавления инфы в структуру на основе фрейма
XNode node = doc.Root.FirstNode;
while (node != null)
{
if (node.NodeType == System.Xml.XmlNodeType.Element) //если элемент
{
XElement element = (XElement)node;
if (element.Name == "Frames")
element.Add(frameElemt);
}
node = node.NextNode;
}
doc.Save("our.xml");
return true;
}