using
System;
using
System.Collections.Generic;
using
System.Xml;
using
System.Text;
using
Sgml;
using
System.IO;
using
System.ComponentModel;
namespace
Freemouse.Base.parser
{
/// <summary>
/// html table 解析器
/// </summary>
public
class
HTMLTableReaderpdf : IDisposable
{
private
List<HTMLTable> table;
private
XmlDocument doc;
private
Encoding objEncoding;
private
SgmlReader reader;
private
byte
[] htmlBytes;
private
bool
disposed =
false
;
private
Component component =
new
Component();
/// <summary>
/// 文本的编码格式
/// </summary>
public
Encoding Encode
{
get
{
return
objEncoding; }
set
{ objEncoding = value; }
}
/// <summary>
/// </summary>
public
List<HTMLTable> Tables
{
get
{
return
table; }
}
/// <summary>
/// </summary>
/// <param name="index">index</param>
/// <returns>HTMLTable</returns>
public
HTMLTable
this
[
int
index]
{
get
{
try
{
return
table[index];
}
catch
(Exception e)
{
throw
e;
}
}
}
/// <summary>
/// 提供文档中表格的索引访问
/// </summary>
/// <param name="index">table index</param>
/// <param name="subindex">tr index</param>
/// <returns>HTMLTr</returns>
public
HTMLTr
this
[
int
index,
int
subindex]
{
get
{
try
{
return
table[index].Rows[subindex];
}
catch
(Exception e)
{
throw
e;
}
}
}
/// <summary>
/// 提供文档中表格的索引访问
/// </summary>
/// <param name="index">table index</param>
/// <param name="subindex">tr index</param>
/// <param name="subindex">td index</param>
/// <returns>HTMLTd</returns>
public
HTMLTd
this
[
int
index,
int
subindex,
int
ssubindex]
{
get
{
try
{
return
table[index].Rows[subindex].Cells[ssubindex];
}
catch
(Exception e)
{
throw
e;
}
}
}
private
Stream outStream;
/// <summary>
/// 提供格式化后的标准html文档流,以供保存
/// </summary>
public
Stream OutputStream
{
get
{
return
outStream; }
set
{ outStream = value; }
}
/// <summary>
/// 构造函数
/// </summary>
public
HTMLTableReader()
{
doc =
new
XmlDocument();
table =
new
List<HTMLTable>();
reader =
new
SgmlReader();
reader.DocType =
"strict"
;
objEncoding = Encoding.Default;
outStream =
new
MemoryStream();
}
/// <summary>
/// 析构函数
/// </summary>
~HTMLTableReader()
{
try
{
if
(reader !=
null
)
{
reader.Close();
}
if
(outStream !=
null
)
{
outStream.Close();
}
}
catch
(Exception e)
{
throw
e;
}
}
/// <summary>
/// 释放所有资源
/// </summary>
public
void
Dispose()
{
Dispose(
true
);
GC.SuppressFinalize(
this
);
}
private
void
Dispose(
bool
disposing)
{
if
(!
this
.disposed)
{
if
(disposing)
{
component.Dispose();
}
disposed =
true
;
}
}
/// <summary>
请发表评论