예제 #1
0
        public XmlDocument LoadXmlDocumentFromStream(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            bool succeeded = false;

            try
            {
                XmlDocument result;
                stream = TestUtil.EnsureStreamWithSeek(stream);
                if (this == JsonLight)
                {
                    result = JsonValidator.ConvertToXmlDocument(stream);
                }
                else if (this == Atom)
                {
                    XmlDocument document = new XmlDocument(TestUtil.TestNameTable);
                    document.Load(stream);
                    result = document;
                }
                else
                {
                    throw new NotSupportedException("XmlDocument creation not supported for serialization format " + this.Name);
                }

                succeeded = true;
                return(result);
            }
            finally
            {
                if (!succeeded)
                {
                    if (stream.CanSeek)
                    {
                        stream.Position = 0;
                        Trace.WriteLine("Failing document:");
                        Trace.Indent();
                        Trace.WriteLine(new StreamReader(stream).ReadToEnd());
                        Trace.Unindent();
                    }
                }
            }
        }