EDN Admin
Well-known member
Hi.
I have a xml file that gets updated frequently. The file is written to using XElement.Save(filename) method in C#. The file gets corrupted everytime somebody randomly does a hard reboot of the system or a hard shutdown or when some service craps out with
blue screen. The xml file corruption error comes up as:
----------------
System.Xml.XmlException: ., hexadecimal value 0x00, is an invalid character. Line 1, position 1.:<br/>
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)<br/>
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()<br/>
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()<br/>
at System.Xml.XmlReader.MoveToContent()<br/>
at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)<br/>
at System.Xml.Linq.XElement.Load(String uri, LoadOptions options)
----------------
I would like to prevent writing of corrupted xml to the file and would like to perform a check of the xml for being a well formed xml before writing it to the file. I was wondering how I could do a check for xml using C#. Note there is no xsd for the xml
and wont be checking it against any xsd.
The follow up question is why does only the xml file get corrupted and not any other text file during random system reboots or shutdowns or blue screens and if there is any C# method call that could prevent corruption of file.
Thanks.
View the full article
I have a xml file that gets updated frequently. The file is written to using XElement.Save(filename) method in C#. The file gets corrupted everytime somebody randomly does a hard reboot of the system or a hard shutdown or when some service craps out with
blue screen. The xml file corruption error comes up as:
----------------
System.Xml.XmlException: ., hexadecimal value 0x00, is an invalid character. Line 1, position 1.:<br/>
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)<br/>
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()<br/>
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()<br/>
at System.Xml.XmlReader.MoveToContent()<br/>
at System.Xml.Linq.XElement.Load(XmlReader reader, LoadOptions options)<br/>
at System.Xml.Linq.XElement.Load(String uri, LoadOptions options)
----------------
I would like to prevent writing of corrupted xml to the file and would like to perform a check of the xml for being a well formed xml before writing it to the file. I was wondering how I could do a check for xml using C#. Note there is no xsd for the xml
and wont be checking it against any xsd.
The follow up question is why does only the xml file get corrupted and not any other text file during random system reboots or shutdowns or blue screens and if there is any C# method call that could prevent corruption of file.
Thanks.
View the full article