I am facing a problem to read HTML string in XmlReader with some reader settings.
Project details :
.Net Standard 2.0 target project
Issue details:
Below exception message thrown when creating XmlReader with settings as per the code snippet.
"System.Xml.Schema.XmlSchemaValidationException
HResult=0x80131941
Message=The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared."
Exception thrown in line : XmlReader reader = XmlReader.Create(new StringReader(html), settings);
Code snippet:
Project details :
.Net Standard 2.0 target project
Issue details:
Below exception message thrown when creating XmlReader with settings as per the code snippet.
"System.Xml.Schema.XmlSchemaValidationException
HResult=0x80131941
Message=The 'http://www.w3.org/XML/1998/namespace:lang' attribute is not declared."
Exception thrown in line : XmlReader reader = XmlReader.Create(new StringReader(html), settings);
Code snippet:
The mentioned exception doesn't throws in WindowsForms application for the same code. Is there any limitation for .Net Standard 2.0 ? Or Is any other approach to achieve my requirement in .Net Standard 2.0?FileStream stream = new FileStream("xhtml1-transitional.xsd", FileMode.Open, FileAccess.ReadWrite); XmlSchema schema = XmlSchema.Read(stream, new ValidationEventHandler(OnValidation)); XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.Schemas.Add(schema); string html = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title></title></head><body><p>hello</p></body></html>";
XmlReader reader = XmlReader.Create(new StringReader(html), settings);
XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(reader); reader.Close();