There can be no text or space before the declaration of the encoding <?xml ?> Other than the specification, and without text between the declaration and the root element other than line break.
Everything else is an invalid document.
UPDATE:
I think your expectation of XmlTextReader.read () is wrong.
Each call to XmlTextReader.Read () goes through the next "token" in the XML document, one token at a time. "Token" means XML elements, spaces, text, and XML encoding declaration.
Your call to reader.ReadOuterXML () returns an empty string because the first token in your XML file is an XML declaration, and there is no OuterXML in the XML declaration.
Consider this code:
XmlTextReader reader = new XmlTextReader("test.xml"); reader.Read(); Console.WriteLine(reader.NodeType); // XMLDeclaration reader.Read(); Console.WriteLine(reader.NodeType); // Whitespace reader.Read(); Console.WriteLine(reader.NodeType); // Element string rs = reader.ReadOuterXml();
The above code produces this output:
XmlDeclaration Whitespace Element
The first token is an XML declaration.
The second token encountered is a line break after an XML declaration.
The third token is found in the <s:Envelope> element. From here, calling the .ReadOuterXML () reader will return what I think you expect to see is the text of the <s:Envelope> element, which is the entire soap package.
If you really want to load the XML file into memory as objects, just call var doc = XDocument.Load("test.xml") and do it with a single swipe.
If you are not working with an XML document that is so monstrously huge that it will not fit into system memory, there are really not many reasons to peek into an XML document for one token at a time.