Organize HTML documents into standard XML documents

Source: Internet
Author: User

There are multiple methods available in.. NET platform for HTML file parsing and data extraction. The simplest and safest way is to first use tools to organize HTML documents into XML documents, then, use the xml dom model or XPath to process data flexibly. SGML is a tool library for HTML Document Sorting:

Microsoft XML Master Chris Lovett has developed a SGML parser called sgmlreader, which can parse HTML files and even convert them into a standard format structure. Sgmlreader is derived from xmlreader, which means that you can parse HTML files like using classes such as xmltextreader to parse XML files.

Here is a sample code:

Public static xmldocument converthtmltoxml (string HTML)

Using (sgmlreader = new sgmlreader ()){

Sgmlreader. doctype = "html ";

Sgmlreader. inputstream = new stringreader (HTML );

Using (stringwriter = new stringwriter ()){

Using (xmltextwriter xmlwriter = new xmltextwriter (stringwriter ))

{

While (! Sgmlreader. EOF ){

Xmlwriter. writenode (sgmlreader, true );

}

}

}

}

Xmldocument xmldoc = new xmldocument ();

Xmldoc. loadxml (stringwriter. tostring ());

Return xmldoc;

 

Home: http://code.msdn.microsoft.com/SgmlReader

 

Language: English authorization form: Open Source

 

Related urls:

Http://msdn.microsoft.com/en-us/library/aa302299.aspx

 

Download Page (SourceForge) sgmlreader 1.8 msdn code library

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.