XDocument can’t load a simple xml with version 1.1

November 26th, 2009 | by | technology

Nov
26

using System;
using System.Xml.Linq;

class Test
{
  static void Main(string[] args)
  {
    string xml = "<?xml version=\"1.1\" ?><root><sub /></root>";
    XDocument doc = XDocument.Parse(xml);
    Console.WriteLine(doc);
  }
}

 

Unhandled Exception:
  System.Xml.XmlException: Version number '1.1' is invalid. Line 1, position 16.
  at System.Xml.XmlTextReaderImpl.Throw(Exception e)
  at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
  at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl)
  at System.Xml.XmlTextReaderImpl.Read()
  at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
  at System.Xml.Linq.XDocument.Parse(String text, LoadOptions options)
  at System.Xml.Linq.XDocument.Parse(String text)
  at Test.Main(String[] args)

No wonder, with this type of hardcoding values (e.g. version) and such poor quality of XML parsers used by Microsoft, Internet explorer can’t load a plain (‘hello world’ equivalent) XHTML page.

No Comments »