Parses the provided xml/html document into discrete components and provides the information to the provided reader, see XmlLightDocument
Syntax
Parameters
- content
- format
- reader
Example
Library/Library.Test/TestHtmlParser.cs
C# | Copy Code |
---|
string[] files = Directory.GetFiles(@"c:\temp\trash", "*.htm", SearchOption.AllDirectories);
System.Diagnostics.Stopwatch sw;
for (int i = 0; i < 10; i++)
{
//HTML Parser
sw = new System.Diagnostics.Stopwatch();
sw.Start();
foreach (string file in files)
new HtmlLightDocument(File.ReadAllText(file));
Console.WriteLine("HTML = {0}", sw.ElapsedMilliseconds);
//XML Parser
sw = new System.Diagnostics.Stopwatch();
sw.Start();
foreach (string file in files)
new XmlLightDocument(File.ReadAllText(file));
Console.WriteLine("XHTM = {0}", sw.ElapsedMilliseconds);
//Parse Only
sw = new System.Diagnostics.Stopwatch();
sw.Start();
IXmlLightReader rdr = new EmptyReader();
foreach (string file in files)
XmlLightParser.Parse(File.ReadAllText(file), XmlLightParser.AttributeFormat.Xml, rdr);
Console.WriteLine("NDOM = {0}", sw.ElapsedMilliseconds);
//Text Only
sw = new System.Diagnostics.Stopwatch();
sw.Start();
foreach (string file in files)
XmlLightParser.ParseText(File.ReadAllText(file));
Console.WriteLine("TEXT = {0}", sw.ElapsedMilliseconds);
} |
VB.NET | Copy Code |
---|
Dim files As String() = Directory.GetFiles("c:\temp\trash", "*.htm", SearchOption.AllDirectories)
Dim sw As System.Diagnostics.Stopwatch
Dim i As Integer = 0
While i < 10
'HTML Parser
sw = New System.Diagnostics.Stopwatch()
sw.Start()
For Each file As String In files
New HtmlLightDocument(File.ReadAllText(file))
Next
Console.WriteLine("HTML = {0}", sw.ElapsedMilliseconds)
'XML Parser
sw = New System.Diagnostics.Stopwatch()
sw.Start()
For Each file As String In files
New XmlLightDocument(File.ReadAllText(file))
Next
Console.WriteLine("XHTM = {0}", sw.ElapsedMilliseconds)
'Parse Only
sw = New System.Diagnostics.Stopwatch()
sw.Start()
Dim rdr As IXmlLightReader = New EmptyReader()
For Each file As String In files
XmlLightParser.Parse(File.ReadAllText(file), XmlLightParser.AttributeFormat.Xml, rdr)
Next
Console.WriteLine("NDOM = {0}", sw.ElapsedMilliseconds)
'Text Only
sw = New System.Diagnostics.Stopwatch()
sw.Start()
For Each file As String In files
XmlLightParser.ParseText(File.ReadAllText(file))
Next
Console.WriteLine("TEXT = {0}", sw.ElapsedMilliseconds)
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also