Пример #1
0
        public void Test_fragment_parsing()
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.ConformanceLevel = ConformanceLevel.Fragment;
            StringReader stream = new StringReader("<html><head></head><body></body></html> <script></script>");

            int        count  = 0;
            SgmlReader reader = new SgmlReader(settings);

            reader.DocType     = "html";
            reader.InputStream = stream;
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    XDocument doc = XDocument.Load(reader.ReadSubtree());
                    Debug.WriteLine(doc.ToString());
                    count++;
                }
            }
            Assert.AreEqual(2, count, "Expecing 2 XmlDocuments in the input stream");
        }