Htmlagilitypack Official document (vi) "Utilities"

Source: Internet
Author: User

HTMLDocument Practical Tools HTMLDocument method

name Description
Detectencoding (Stream) Detects the encoding of an HTML stream.
Detectencoding (TextReader) Detects the encoding of HTML text provided on a TextReader.
Detectencoding (String) Detects the encoding of an HTML file.
Detectencodingandload (String) Detects the encoding of HTML document from a file, and then loads the file.
Detectencodingandload (String, Boolean) Detects the encoding of HTML document from a file, and then loads the file.
Public Encoding detectencoding (Stream stream)

Detects the encoding of the HTML stream. The Detectencoding method is a member parameter of the htmlagilitypack.htmldocument :

Stream: the input stream. cannot be null. return:

The detected encoding.

The following example detects the encoding of the HTML stream.

var htmlnewdoc = new HTMLDocument ();

FileStream Newfs = new FileStream ("test.html", FileMode.Open);

var encoding = htmlnewdoc.detectencoding (NEWFS);
Public Encoding detectencoding (TextReader reader)

Detects the encoding of the HTML text provided on the TextReader. The Detectencoding method is a member parameter of the htmlagilitypack.htmldocument :

Reader: A textreader used to provide HTML. cannot be null. return:

The detected encoding.

The following example detects the encoding of the HTML text provided on TextReader.

var htmlnewdoc = new HTMLDocument ();

TextReader tr = file.opentext ("test.html");

var encoding = htmlnewdoc.detectencoding (TR);
Public Encoding detectencoding (string path)

Detects the encoding of an HTML file. The Detectencoding method is a member parameter of the htmlagilitypack.htmldocument :

Paths: The path to the file that contains the HTML document to be instrumented. cannot be null. return:

The detected encoding.

The following example detects the encoding of an HTML file.

var htmlnewdoc = new HTMLDocument ();

var encoding = htmlnewdoc.detectencoding ("test.html");
Public void Detectencodingandload (string path)

First, the encoding of the HTML document is detected from the file, and then the file is loaded. The Detectencodingandload method is a member parameter of the htmlagilitypack.htmldocument :

Path: The full file path to read.

The following example first detects the encoding of an HTML file and then loads it.

var htmlnewdoc = new HTMLDocument ();

Htmlnewdoc.detectencodingandload ("test.html");
Public void Detectencodingandload (string path, bool detectencoding)

Detects the encoding of HTML document from a file, and then loads the file. Detectencodingandload method is a htmlagilitypack.htmldocument
First, the encoding of the HTML document is detected from the file, and then the file is loaded. The Detectencodingandload method is a member parameter of the htmlagilitypack.htmldocument :

Path: The full file path to read. cannot be null.
Detectencoding: The detection encoding is true, or false.

The following example first detects the encoding of an HTML file and then loads it.

var htmlnewdoc = new HTMLDocument ();

Htmlnewdoc.detectencodingandload ("test.html", true);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.