Created
July 12, 2011 01:50
-
-
Save bdallen/1077236 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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