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); } }
public void TestHtmlEntityRef() { string html = @"<html> <body attrib=""this & that ><  !""> this char '<' and this one '>' and this one '&' should be encoded. We encoded ' ' and à and ' ' and ' ' all by ourselves. This in not valid xml �, nor is �, 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; g; &#-123;. </body> </html>"; string expect = @"<html><body attrib=""this & that ><" + (Char)160 + @" !""> this char '<' and this one '>' and this one '&' should be encoded. We encoded ' ' and à and ' ' and ' ' all by ourselves. This in not valid xml �, nor is �, 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>"; 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); }