I have a product database in XML. For each product I have its width W, height H and price P.
Given a product with W, H and P, I want to count the number of products with width less than W, and separate counts for those with height < H and those with price < P. Meaning 3 separate and independent numbers resulting from counting.
What is an efficient way to do so using C#? Obviously, I want to go through each element in the XML file only once.
XML file is made up of following nodes and has been read into an XDocument object:
<product><name>abc</name><W>7</W><H>3</H><P>40</P></product>
Something like this would work
This has no safeguards though, so if your product element does not contain an integer value for each of the H,W and P elements (or one of these elements does not exists), it will break. You’d need to add some null and conversion checking.