I am new to C# and am kind of confused what to do after reading some related posts about this topic.
I am giving an XML file from another tool. The XML file may not be valid as it may contain illegal characters and could be not well-formed. Unfortunately, the correction of illegal characters won't be done as the XML is generated from this other tool since it [ the tool ] has very bad memory leaks and a weak API.
My initial idea was to use "XmlTextReader" to read the XML file, visit each element and then correct the element value, if needed. My dream came to a halt because I learn that I am unable to configure turning off any exceptions while reading a XML file.
So, my other idea is to read each line of the XML file as a string and do some type of pattern matching to get the element's value to determine if any corrections have to be done. A element value may not be all on one line.
Can anyone point me to any C# libraries/functions I should be reading about in order to do what I want? One thing I do know is all the possible element values that can be in a XML file in advance.
Thanks ahead.
If it is useful, here are some of the element tag formats. Each tag I need to match will begin with "mon:Field name =""
<code>
< mon:Field name="Modified By" >Administrator< /mon:Field >
</code>
<code>
< mon:Field name="Modified On">Wednesday, May 12, 2010< /mon:Field>
</code>
</code>
< mon:Field name="Value">I went to the store
I bought two eggs
I bought one ham< /mon:Field>
</code>
EDIT
Since my post I did some more searching online. I came across this code that looks useful that I am now studying. ( I have read the stackoverflow posts already why you should't parse XML with regular expressions but it seems like my only hope here ).
http://en.csharp-online.net/CSharp_Regular_Expression_Recipes%E2%80%94Enumerating_Matches