My application needs to parse XML files provided by the user, so I don't have control over its quality.
I have an XML which is incorrect, snippet I have shared below. Notice the missing prefix, xmlns:=
<?xml version="1.0" encoding="utf-8" ?>
<ncx version="2005-1" xml:lang="por" xmlns:="http://www.daisy.org/z3986/2005/ncx/">
</ncx>
When I try to use XDocument.Load()
in C#, it throws this exception and rightly so -
System.Xml.XmlException: 'Name cannot begin with the '=' character, hexadecimal value 0x3D. Line 2, position 44.'
Is there a way I can correct such minor errors in the XML? I tried looking for it but didn't find any good solution. And I want to avoid string search/replace to fix such errors.