I have an SslStream from which I receive spontaneous XML messages. I want to use XmlTextReader to process XML messages from that stream. Unfortunately it allows me reading only 1st XML. When I call Read after the 1st xml is received, the method throws an exception:
Multiple roots in XML documents (“Xml_MultipleRoots”). I believe this is a problem that the stream provides xml messages one by one but the XmlTextReader can handle only one.
How to fix this?
I have an SslStream from which I receive spontaneous XML messages. I want to
Share
First of all, don’t use
new XmlTextReader()anymore. UseXmlReader.Create(), which has been the preferred way to create anXmlReadersince .NET 2.0.Second, use the overload of
Createthat accepts anXmlReaderSettingsobject: