Find highest XML value in <p x="-0.979248" y="-0.00141319" />
-
-
Hi all, I have a XML files that looks like this: ... <dataset> ... <p x="-0.979248" y="-0.00141319" /> ... </dataset> ... I need to find the highest value of y. The files have 100 000 rows so it should be reasonable fast. But any suggestions are welcome.
Hi, first of all i wouldn't use an XML-class to load the dataset, this will be propably to slow. Try to use a stream to read the file line by line. There you could extract the y-value using a regular expression, or if all values have the same length (y is at the same index in every line) access it by its index. Then store the highest y-value somewhere and compare every y-value with this one. If the current y-value is higher overwrite the stored value. This algorithm has a complexity of O(n). If you are using multiple processors you could think about splitting the file in two or more parts and use threads to accomplish the task. Hope this helps you a bit. Regards Sebastian
It's not a bug, it's a feature! Me in Softwareland.
-
Hi, first of all i wouldn't use an XML-class to load the dataset, this will be propably to slow. Try to use a stream to read the file line by line. There you could extract the y-value using a regular expression, or if all values have the same length (y is at the same index in every line) access it by its index. Then store the highest y-value somewhere and compare every y-value with this one. If the current y-value is higher overwrite the stored value. This algorithm has a complexity of O(n). If you are using multiple processors you could think about splitting the file in two or more parts and use threads to accomplish the task. Hope this helps you a bit. Regards Sebastian
It's not a bug, it's a feature! Me in Softwareland.
Ah, OK. This was my first idea to solve the problem. But being an "old style" .net programmer I thought there was a more effective built in way to do it. Stream and loop, simple enough...
I'll skip the regex and find the position fo "y = " and "/>" and grab the string between those positions.