I have a program which runs tests and generates a grid-view with all the results in it, and also an XML log file. The program also has the functionality to load logs to replicate the grid-view.
Since the program writes to the log file as its executing, if it crashes the log file will be missing closing tags. I still want to be able to load these XML files though as there is still lots of valuable data that can help me find out what caused the crash.
I was thinking maybe going through the XML file and closing off any unclosed XML tag, or maybe writing some kind of “Dirty” XML reader that would pretend every tag was closed. Any ideas on what I could do or how I should proceed?
Edit:
<Root>
<Parent>
<Child Name="One">
<Foo>...</Foo>
<Bar>...</Bar>
<Baz>...</Baz>
</Child>
<Child Name="Two">
<Foo>...</Foo>
<Bar>...</Bar>
!-- Crash happens here --!
From this I would still look to produce
Child Foo Bar Baz
One ... ... ...
Two ... ... /
Presumably it’s all valid until it’s truncated… so using
XmlReadercould work… just be prepared to handle it going bang when it reaches the truncation point.Now the
XmlReaderAPI isn’t terribly pleasant (IMO) so you might want to move to the start of some interesting data (which would have to be complete in itself) and then call theXNode.ReadFrom(XmlReader)method to get that data in a simple-to-use form. Then move to the start of the next element and do the same, etc.Sample code:
Sample XML:
Sample output:
Got child: First child
Got child: Second child
So obviously you’d want to catch the exception, but you can see that it managed to read the first two elements correctly.