System.Xml or System.Linq to check if the attributes count are in order

JannetTwelves

New Member
I have this example xml:\[code\]<tr:secmain> <fn:footnote num ="1"> <fn:footnote num ="2"> <fn:footnote num ="3"> <fn:footnote num ="3"> <fn:footnote num ="5"></tr:secmain><tr:secmain> <fn:footnote num ="1"> <fn:footnote num ="2"> <fn:footnote num ="3"> <fn:footnote num ="4"> <fn:footnote num ="6"></tr:secmain>\[/code\]For every element I need to check if all footnotes are in order and if errors are found I need to check where this line appears. In the example the line errors are Line 5 and Line 13. Right now I am currently checking for errors using Linq, by extracting all the the numbers to other textfile and check the incorrect lines with this method: \[code\]int[] IncorrectLines(string filename){ // Parse the file into an array of ints, 10* each version number. var ints = File.ReadLines(filename) .Select(s => (int)(10 * decimal.Parse(s))).ToArray(); // Pair each number up with the previous one. var pairs = ints .Zip(ints.Skip(1), (p, c) => new { Current = c, Previous = p }); // Include the line numbers var withLineNos = pairs .Select((pair, index) => new { Pair = pair, LineNo = index + 2 }); // Only keep incorrect lines var incorrect = withLineNos.Where(o => o.Pair.Current - 1 != o.Pair.Previous && // not a simple increment o.Pair.Current % 10 != 0); // not a whole new version // Return the line numbers; could return (double)o.Pair.Current / 10 instead. return incorrect.Select(o => o.LineNo).ToArray();} \[/code\]But I am having trouble now, because I need to check the sequence for every tr:secmainThanks for all of your advice. :)edit:The footnotes can be in this order: (Just a sample)\[code\]12 2.1 2.2 2.33 3.1 3.2 3.3 3.4 3.5 3.745etc.\[/code\]
 
Back
Top