Last post Apr 08, 2010 04:13 PM by atconway
Apr 07, 2010 05:30 AM|mattt|LINK
Okay, I've got a number of product mappings in an XML file. The file contains the name of the product and what category it maps to in each of three different online merchants that we supply.
I need to build some code to write out xml feeds for each of these merchants. What's worrying me about this is the most effecient way to do it: having to step through an entire XML file for *each product* until a match is found is clearly very resource intensive,
and I have to do it in triplicate because we've got three merchants. That's a whole load of overhead.
1) There must be a better way of checking the data each time than re-reading the XML file for each product. Load it into a dictionary or something - but can anyone suggest what's likely to be the most effecient option and why?
2) Can anyone suggest how I can organise the code so I only need to read the xml file once and then re-use it for each merchant?
Apr 08, 2010 04:13 PM|atconway|LINK
Yes, the most efficient way of reading that XML document is going to be by using
LINQ to XML. It is much improved and streamlined code as opposed to writing old XPath code to navigate a XML file. Reading the XML document directly into a list of objects is a slick way of getting the data into a manageable piece. Take a
look at the following for more information:
Using LINQ to XML:
LINQ to XML:
Now as far as persisting the data from the XML document after reading the data, you could save it in an Application variable that spans all ASP.NET clients, serialize the object to SQL Server, save it in Session if it is client specific, etc.