Parameters
- wtr
Library/Library.Test/TestHtmlParser.cs
C# | Copy Code |
---|---|
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); |
VB.NET | Copy Code |
---|---|
Dim html As String = "<html>" & vbCr & vbLf & " <body attrib=""this & that ><  !"">" & vbCr & vbLf & " this char '<' and this one '>' and this one '&' should be encoded. " & vbCr & vbLf & " We encoded ' ' and à and ' ' and ' ' all by ourselves." & vbCr & vbLf & " This in not valid xml �, nor is �, but we still allow it." & vbCr & vbLf & " This entity name will pass-through &unknown; this will not &whateverthatmeans;" & vbCr & vbLf & " and nor will these &; &#; &h; &l t; &1two; &234; g; &#-123;." & vbCr & vbLf & " </body>" & vbCr & vbLf & " </html>" Dim expect As String = "<html><body attrib=""this & that ><" + DirectCast(160, [Char]) + " !"">" & vbCr & vbLf & " this char '<' and this one '>' and this one '&' should be encoded. " & vbCr & vbLf & " We encoded ' ' and à and ' ' and ' ' all by ourselves." & vbCr & vbLf & " This in not valid xml �, nor is �, but we still allow it." & vbCr & vbLf & " This entity name will pass-through &unknown; this will not &whateverthatmeans;" & vbCr & vbLf & " and nor will these &; &#; &h; &l t; &1two; &234; &#x00fg; &#-123;." & vbCr & vbLf & " </body></html>" Dim doc As XmlLightDocument = New HtmlLightDocument(html) Dim settings As New XmlWriterSettings() With { _ Key .CheckCharacters = True, _ Key .Indent = False, _ Key .IndentChars = "", _ Key .NewLineChars = "", _ Key .NewLineHandling = NewLineHandling.None, _ Key .OmitXmlDeclaration = True, _ Key .CloseOutput = False _ } Dim sw As New StringWriter() Dim wtr As XmlWriter = XmlWriter.Create(sw, settings) doc.WriteXml(wtr) wtr.Flush() Dim xml As String = sw.ToString() Assert.AreEqual(expect, xml) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7