CSharpTest.Net
HtmlLightDocument Constructor()
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Html Namespace > HtmlLightDocument Class > HtmlLightDocument Constructor : HtmlLightDocument Constructor()

Glossary Item Box

Represents a loosly parsed html document

Syntax

Visual Basic (Declaration) 
Public Function New()
C# 
public HtmlLightDocument()

Example

Library/Library.Test/TestHtmlParser.cs

C#Copy Code
string notxml = "<html id=a ><body foo='bar' bar=\"foo\" />";

HtmlLightDocument html = new HtmlLightDocument();
XmlLightParser.Parse(notxml, html);
Assert.AreEqual("html", html.Root.TagName);
Assert.AreEqual(1, html.Root.Attributes.Count);
Assert.AreEqual("a", html.Root.Attributes["id"]);
Assert.AreEqual(1, html.Root.Children.Count);
Assert.AreEqual("body", html.Root.Children[0].TagName);
Assert.AreEqual("foo", html.Root.Children[0].Attributes["bar"]);
Assert.AreEqual("bar", html.Root.Children[0].Attributes["foo"]);

XmlLightDocument xml = new XmlLightDocument();
XmlLightParser.Parse(notxml, XmlLightParser.AttributeFormat.Xml, xml);
Assert.AreEqual(2, xml.Root.Attributes.Count);
//Not recognized: xml.Root.Attributes["id"]
Assert.AreEqual("body", xml.Root.TagName);
Assert.AreEqual("foo", xml.Root.Attributes["bar"]);
Assert.AreEqual("bar", xml.Root.Attributes["foo"]);
VB.NETCopy Code
Dim notxml As String = "<html id=a ><body foo='bar' bar=""foo"" />"

Dim html As New HtmlLightDocument()
XmlLightParser.Parse(notxml, html)
Assert.AreEqual("html", html.Root.TagName)
Assert.AreEqual(1, html.Root.Attributes.Count)
Assert.AreEqual("a", html.Root.Attributes("id"))
Assert.AreEqual(1, html.Root.Children.Count)
Assert.AreEqual("body", html.Root.Children(0).TagName)
Assert.AreEqual("foo", html.Root.Children(0).Attributes("bar"))
Assert.AreEqual("bar", html.Root.Children(0).Attributes("foo"))

Dim xml As New XmlLightDocument()
XmlLightParser.Parse(notxml, XmlLightParser.AttributeFormat.Xml, xml)
Assert.AreEqual(2, xml.Root.Attributes.Count)
'Not recognized: xml.Root.Attributes["id"]
Assert.AreEqual("body", xml.Root.TagName)
Assert.AreEqual("foo", xml.Root.Attributes("bar"))
Assert.AreEqual("bar", xml.Root.Attributes("foo"))

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys