Deliverable 2 – INFO 320

XML / C# Diary

Ryan Prins

November 26, 2003

 

  1. Define what color will go on what colored pages.
    1. Code Example:

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");

 

  1. Open a steam to the original XML document from deliverable one and stat the new XML file with this data.
    1. Code Example:

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);

                        }

 

  1. Create new streams to the other 4 new files and get the needed information from these files and add it to the bottom of the new XML source.
    1. Code Example:

// 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);

                  }

 

  1. Do a regular expression check on the colors that are found in the XML files.
    1. Code Example:

                  Regex regularExpression;

                        Match m;

                        regularExpression = new Regex("(pink|orange|yellow|white|red|peach|raspberry|scarlet)", RegexOptions.IgnoreCase);

                  m = regularExpression.Match(description);

 

  1. Make sure that that the data is in the proper format, and insert the color that will be output on the page as an attribute to the flower element. Also, close the elements and the XML source.
    1. Code Example:

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();