Skip to content

Instantly share code, notes, and snippets.

@bdallen
Created July 12, 2011 01:50
Show Gist options
  • Save bdallen/1077236 to your computer and use it in GitHub Desktop.
Save bdallen/1077236 to your computer and use it in GitHub Desktop.
public static MemoryStream StockXML(List<CapitalData.DataObjects.StockItem> stockList)
{
MemoryStream ms = new MemoryStream();
MD5 md5 = new MD5CryptoServiceProvider();
Byte[] originalBytes;
Byte[] encodedBytes;
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.NewLineChars = "\r\n";
XmlWriter w = XmlWriter.Create(ms, settings);
w.WriteStartDocument();
w.WriteStartElement("StockItems");
w.WriteAttributeString("Total", stockList.Count.ToString());
foreach (CapitalData.DataObjects.StockItem st in stockList)
{
// calculate the Hash for this product
originalBytes = ASCIIEncoding.ASCII.GetBytes(st.Name + st.Title + st.C + st.D);
encodedBytes = md5.ComputeHash(originalBytes);
w.WriteStartElement("Product");
w.WriteAttributeString("Hash", BitConverter.ToString(encodedBytes));
w.WriteAttributeString("ProdID", st.Name);
w.WriteAttributeString("SellEx", st.C.ToString());
w.WriteAttributeString("SellInc", st.D.ToString());
w.WriteAttributeString("ImageFN", st.Name + ".jpg");
w.WriteString(st.Title);
w.WriteEndElement();
}
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
return ms;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment