Deliverable 2 – INFO 320
XML / C# Diary
Ryan Prins
November 26, 2003
Hashtable colorTable = new Hashtable();
colorTable.Add("pink", "pink");
colorTable.Add("orange", "yellow");
colorTable.Add("yellow", "yellow");
colorTable.Add("white", "white");
colorTable.Add("red", "red");
colorTable.Add("peach", "pink");
colorTable.Add("raspberry", "red");
colorTable.Add("scarlet",
"red");
foreach (XmlNode
d in flowerList1)
{
// Get the different elements within this node
string name = d.ChildNodes[0].InnerText;
string id = d.ChildNodes[1].InnerText;
string description = d.ChildNodes[2].InnerText;
// Get the
attribute data of node
XmlAttributeCollection
ac;
ac = d.Attributes;
// Get the
type of the flower (e.g. rose)
string type = ac["type"].InnerText;
// Send
information to employee method
flower(xwriter, name, id, description, type);
}
// Process target nodes
foreach (XmlNode
d in shipmentList)
{
// Get the
different elements within this node
string name = d.ChildNodes[0].InnerText;
// Get the
attribute data of node
XmlAttributeCollection
ac;
ac = d.Attributes;
// Get the
type of the flower (e.g. rose)
string id = ac["ID"].InnerText;
string type = ac["Type"].InnerText;
// make
description
string description = "No Description
Provided";
if(type.Equals("Dahlia"))
{
XmlNode
myNode = DahliaRoot.SelectSingleNode("/FlowerMania/Descriptions/ID[@Num
= '" + id + "']");
description
= myNode["Text"].InnerText;
}
else if(type.Equals("Begonia"))
{
XmlNode
myNode = BegoniaRoot.SelectSingleNode("/FlowerMania/Descriptions/ID[@Num
= '" + id + "']");
description
= myNode.ChildNodes[0].InnerText;
}
else if(type.Equals("Coleus"))
{
XmlNode
myNode = ColeusRoot.SelectSingleNode("/FlowerMania/Descriptions/ID[@Num
= '" + id + "']");
description
= myNode.ChildNodes[0].InnerText;
}
// Send
information to employee method
flower(xwriter, name, id, description, type);
}
Regex regularExpression;
Match m;
regularExpression
= new Regex("(pink|orange|yellow|white|red|peach|raspberry|scarlet)",
RegexOptions.IgnoreCase);
m
= regularExpression.Match(description);
string flowerColor
= m.Value.ToLower();
string flowerColorXML
= (string)colorTable[flowerColor];
w.WriteStartElement("flower");
w.WriteAttributeString("type",
type);
w.WriteAttributeString("color",
flowerColorXML);
w.WriteElementString("name",
name);
w.WriteElementString("id",
id);
w.WriteElementString("description",
description);
w.WriteEndElement();