Пример #1
0
        public void TestParseDocument()
        {
            XmlLightDocument doc = new HtmlLightDocument(document);
            XmlLightDocument doc2;

            using (TempFile t = new TempFile())
            {
                using (TextWriter tw = new StreamWriter(t.Open()))
                    doc.WriteXml(tw);
                new XhtmlValidation(XhtmlDTDSpecification.XhtmlTransitional_10).Validate(t.TempPath);
                doc2 = new XmlLightDocument(t.ReadAllText());

                Assert.AreEqual(doc.InnerXml, doc2.InnerXml);
            }
        }
Пример #2
0
        public void TestHtmlEntityRef()
        {
            string html   = @"<html>
            <body attrib=""this & that ><&nbsp;&#32;!"">
                this char '<' and this one '>' and this one '&' should be encoded.  
                We encoded ' &nbsp; ' and &Atilde; and '&#32;' and '&#x20;' all by ourselves.
                This in not valid xml &#xffffffff;, nor is &#123456789;, but we still allow it.
                This entity name will pass-through &unknown; this will not &whateverthatmeans;
                and nor will these &; &#; &h; &l t; &1two; &234; &#x00fg; &#-123;.
            </body>
            </html>";
            string expect = @"<html><body attrib=""this &amp; that &gt;&lt;" + (Char)160 + @" !"">
                this char '&lt;' and this one '&gt;' and this one '&amp;' should be encoded.  
                We encoded ' &nbsp; ' and &Atilde; and '&#32;' and '&#x20;' all by ourselves.
                This in not valid xml &#xffffffff;, nor is &#123456789;, but we still allow it.
                This entity name will pass-through &unknown; this will not &amp;whateverthatmeans;
                and nor will these &amp;; &amp;#; &amp;h; &amp;l t; &amp;1two; &amp;234; &amp;#x00fg; &amp;#-123;.
            </body></html>";

            XmlLightDocument  doc      = new HtmlLightDocument(html);
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                CheckCharacters    = true,
                Indent             = false,
                IndentChars        = "",
                NewLineChars       = "",
                NewLineHandling    = NewLineHandling.None,
                OmitXmlDeclaration = true,
                CloseOutput        = false
            };
            StringWriter sw  = new StringWriter();
            XmlWriter    wtr = XmlWriter.Create(sw, settings);

            doc.WriteXml(wtr);
            wtr.Flush();
            string xml = sw.ToString();

            Assert.AreEqual(expect, xml);
        }
Пример #3
0
		public void TestParseDocument()
		{
			XmlLightDocument doc = new HtmlLightDocument(document);
			XmlLightDocument doc2;
			using (TempFile t = new TempFile())
			{
				using (TextWriter tw = new StreamWriter(t.Open()))
					doc.WriteXml(tw);
				new XhtmlValidation(XhtmlDTDSpecification.XhtmlTransitional_10).Validate(t.TempPath);
				doc2 = new XmlLightDocument(t.ReadAllText());

				Assert.AreEqual(doc.InnerXml, doc2.InnerXml);
			}
		}
Пример #4
0
        public void TestHtmlEntityRef()
        {
            string html = @"<html>
            <body attrib=""this & that ><&nbsp;&#32;!"">
                this char '<' and this one '>' and this one '&' should be encoded.  
                We encoded ' &nbsp; ' and &Atilde; and '&#32;' and '&#x20;' all by ourselves.
                This in not valid xml &#xffffffff;, nor is &#123456789;, but we still allow it.
                This entity name will pass-through &unknown; this will not &whateverthatmeans;
                and nor will these &; &#; &h; &l t; &1two; &234; &#x00fg; &#-123;.
            </body>
            </html>";
            string expect = @"<html><body attrib=""this &amp; that &gt;&lt;" + (Char)160 + @" !"">
                this char '&lt;' and this one '&gt;' and this one '&amp;' should be encoded.  
                We encoded ' &nbsp; ' and &Atilde; and '&#32;' and '&#x20;' all by ourselves.
                This in not valid xml &#xffffffff;, nor is &#123456789;, but we still allow it.
                This entity name will pass-through &unknown; this will not &amp;whateverthatmeans;
                and nor will these &amp;; &amp;#; &amp;h; &amp;l t; &amp;1two; &amp;234; &amp;#x00fg; &amp;#-123;.
            </body></html>";

            XmlLightDocument doc = new HtmlLightDocument(html);
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                CheckCharacters = true,
                Indent = false,
                IndentChars = "",
                NewLineChars = "",
                NewLineHandling = NewLineHandling.None,
                OmitXmlDeclaration = true,
                CloseOutput = false
            };
            StringWriter sw = new StringWriter();
            XmlWriter wtr = XmlWriter.Create(sw, settings);
            doc.WriteXml(wtr);
            wtr.Flush();
            string xml = sw.ToString();

            Assert.AreEqual(expect, xml);
        }