using System;
using System.IO;
using System.Xml;
namespace Narcissus
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Class1 c = new Class1();
try
{
// Establish the writer
XmlTextWriter xwriter = new XmlTextWriter("Narcissus.xml", null);
xwriter.Formatting = Formatting.Indented;
xwriter.WriteStartDocument();
xwriter.WriteStartElement("Narcissus");
// Get the input data
XmlDocument pup1 = new XmlDocument();
pup1.Load("DaffodilPup1.xml");
XmlDocument pup2 = new XmlDocument();
pup2.Load("DaffodilPup2.xml");
// Collect target nodes
XmlNodeList flowerList1;
XmlElement root1 = pup1.DocumentElement;
flowerList1 = root1.SelectNodes("/Daffodil/Narcissus");
// Process target nodes
foreach (XmlNode d in flowerList1)
{
string group = d.ChildNodes[2].InnerText;
string year = d.ChildNodes[3].InnerText;
// Get the attribute data of node
XmlAttributeCollection ac;
ac = d.Attributes;
string name = ac["Name"].InnerText;
XmlAttributeCollection acPar;
acPar = d.ParentNode.Attributes;
string supplier = acPar["Supplier"].InnerText;
// Send information to flower write method
c.flowerWrite(xwriter, group, supplier, year, name);
}
// Collect target nodes
XmlNodeList flowerList2;
XmlElement root2 = pup2.DocumentElement;
flowerList2 = root2.SelectNodes("//Name");
// Process target nodes
foreach (XmlNode e in flowerList2)
{
string group = e.ParentNode.Name;
Console.WriteLine("group is " + group);
string year = e.ParentNode.ChildNodes[1].InnerText;
Console.WriteLine("year is " + year);
string name = e.ParentNode.ChildNodes[0].InnerText;
Console.WriteLine("name is " + name);
// Get the attribute data of node
XmlAttributeCollection ac;
ac = e.ParentNode.ParentNode.Attributes;
string supplier = ac["Service"].InnerText;
Console.WriteLine("supplier is " + supplier);
// Send information to flower write method
c.flowerWrite(xwriter, group, supplier, year, name);
}
// Close the writer
xwriter.WriteEndDocument();
xwriter.Close();
}
catch (IOException e)
{
Console.WriteLine(e);
}
}
Class1()
{
}
public void flowerWrite(
XmlTextWriter w,
string inGroup,
string inSupplier,
string inYear,
string inName)
{
w.WriteStartElement(inGroup);
w.WriteStartElement(inSupplier);
w.WriteAttributeString("YEAR",inYear);
w.WriteElementString("NAME", inName);
w.WriteEndElement();
w.WriteEndElement();
}
}
}