Wednesday, 8 June 2016

XML : How to use XmlReader with behavior of XmlTextReader with Namespaces = false

I want to parse 'invalid' xml using a streaming xml parser. I have two options

  1. XmlReader.Create(..., new XmlReaderSettings() { CheckCharacters = false, ConformanceLevel = ConformanceLevel.Fragment, ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.None, ValidationType = ValidationType.None }))

  2. new XmlTextReader(...) { Namespaces = false, Normalization = false })

The first is failing on unrecognized namespaces which are presented in the xml: '...' is an undeclared prefix.

The second is failing on invalid characters: XmlException: '', hexadecimal value 0x13, is an invalid character. Line ...

Is there an option to combine both behaviors (Namespaces = false && CheckCharacters = false) so parsing will not fail on undefined namespaces and invalid characters?

Input "xml" cannot be changed as provided as is. It is also huge and cannot be loaded to the memory.

No comments:

Post a Comment