using System; using System.IO; using System.Xml; namespace LabPuppy9 { class makeXML { [STAThread] static void Main(string[] args) { try { // Establish the writer XmlTextWriter xwriter = new XmlTextWriter("LabPuppy9.xml", null); xwriter.Formatting = Formatting.Indented; xwriter.WriteStartDocument(); xwriter.WriteStartElement("Narcissus"); // Get the input data XmlDocument doc1 = new XmlDocument(); doc1.Load("DaffodilPup1.xml"); XmlDocument doc2 = new XmlDocument(); doc2.Load("DaffodilPup2.xml"); // Collect target nodes XmlNodeList flowerList1; XmlElement root1 = doc1.DocumentElement; flowerList1 = root1.SelectNodes("/Daffodil/Narcissus"); string supplier1 = root1.Attributes.GetNamedItem("Supplier").InnerText; XmlNodeList flowerList2; XmlElement root2 = doc2.DocumentElement; flowerList2 = root2.SelectNodes("/Bulbs/*"); string supplier2 = root2.Attributes.GetNamedItem("Service").InnerText; // Process target nodes foreach (XmlNode d in flowerList1) { string year = d.ChildNodes[3].InnerText; string group = d.ChildNodes[2].InnerText; // Get the attribute data of node XmlAttributeCollection ac; ac = d.Attributes; string name = ac["Name"].InnerText; // Send information to employee method flower(xwriter, supplier1, year, group, name); } foreach (XmlNode d in flowerList2) { string year = d.ChildNodes[1].InnerText; string name = d.ChildNodes[0].InnerText; string group = d.Name; // Get the attribute data of node XmlAttributeCollection ac; ac = d.Attributes; // Send information to employee method flower(xwriter, supplier2, year, group, name); } // Close the writer xwriter.WriteEndDocument(); xwriter.Close(); } catch (IOException e) { Console.WriteLine(e); } } public static void flower(XmlTextWriter w, string company, string year, string group, string name) { w.WriteStartElement(group); w.WriteStartElement(company); w.WriteAttributeString("Year",year); w.WriteElementString("Name", name); w.WriteEndElement(); w.WriteEndElement(); } } }