using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace CreateXML
{
class Program
{
static void Main(string[] args)
{
if (File.Exists("1.xml"))
{
File.Delete("1.xml");
}
XmlDocument xmlDoc = new XmlDocument();
XmlNode xmlNode = xmlDoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
XmlNode myNode = xmlDoc.CreateNode(XmlNodeType.Element, "appSetting", "");
xmlDoc.AppendChild(xmlNode);
xmlDoc.AppendChild(myNode);
for (int i = 0; i < 10; i++)
{
XmlElement xmlElement = xmlDoc.CreateElement("", "test" + i.ToString(), "");
xmlElement.InnerText = "Visible";
XmlAttribute xmlAttribute = xmlDoc.CreateAttribute("width");
xmlAttribute.Value = "10";
xmlElement.Attributes.Append(xmlAttribute);
myNode.AppendChild(xmlElement);
}
xmlDoc.Save("1.xml");
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load("1.xml");
File.Delete("1.xml");
XmlDocument xmlDoc1 = new XmlDocument();
XmlNode xmlNode1 = xmlDoc1.CreateNode(XmlNodeType.XmlDeclaration, "", "");
XmlNode myNode1 = xmlDoc1.CreateNode(XmlNodeType.Element, "appSetting", "");
xmlDoc1.AppendChild(xmlNode1);
xmlDoc1.AppendChild(myNode1);
XmlNode root = xmlDocument.SelectSingleNode("appSetting");
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>()
{
{ "test3","test3"},
{ "test4","test4"},
{ "test5","test5"},
{ "test6","test6"},
{ "test7","test7"},
{ "test8","test8"},
{ "test9","test9"},
{ "test0","test0"},
{ "test1","test1"},
{ "test2","test2"},
};
XmlNodeList list = root.ChildNodes;
var queue = new Queue<XmlNode>();
foreach (KeyValuePair<string, string> item in keyValuePairs)
{
for (int i = 0; i < list.Count - 1; i++)
{
if (list[i].Name == item.Value)
{
queue.Enqueue(list[i]);
}
}
}
while (queue.Count != 0)
{
myNode1.AppendChild(xmlDoc1.ImportNode(queue.Dequeue(), true));
}
xmlDoc1.Save("1.xml");
}
}
}