Convert HTML files into XML files

Source: Internet
Author: User
Tags tidy

ImportJava. Io. bufferedinputstream;

ImportJava. Io. fileoutputstream;

ImportJava. Io. filewriter;

ImportJava. Io. ioexception;

ImportJava. Io. printwriter;

ImportJava.net. url;

ImportOrg. W3C. Tidy. Tidy;

Public ClassHtml2xml {

PrivateStringURL;

PrivateStringOutfilename;

PrivateStringErroutfilename;

PublicHtml2xml (string URL, string outfilename, string erroutfilename ){

This . URL = URL; /// provides an ingress URL

This . outfilename = outfilename; /// export a file

This.Erroutfilename= Erroutfilename;//Zookeeper File

}

Public static void main (string [] ARGs) {

/// metric data: HTML file utl , export the file and upload the file name

system. out . println ( " Program Start Operation ...... " );

html2xml T = New html2xml ( " http: // hswebuat01/Maximo/help.html " ,

"C: \ temp \ html2xml. xml","C: \ temp \ err.txt");

T. Convert ();

System.Out. Println ("End of program operation...... ");

}

Public VoidConvert (){

Url u;

Bufferedinputstream in;

Fileoutputstream out;

tidy = New tidy ();

tidy. setxmlout ( true ); /// notification tidy about HTML scaled to XML

Try{

Tidy. seterrout ( New Printwriter ( New Filewriter ( Erroutfilename ), True )); // Save zookeeper information to a file

U =NewURL (URL);

In = New bufferedinputstream (U. openstream (); /// Create a sequence to input and output streams

Out =NewFileoutputstream (Outfilename);

Tidy. parse (In, out );//Zookeeper File

In. Close ();

Out. Close ();

}Catch(Ioexception e ){

System.Out. Println (This. Tostring () + E. tostring ());

}

}

}

 

 

 

 

/Files/snowfun/html2xml.zip

// Files/snowfun/jtidy-r938.zip

Key points:

(1) bufferedinputstream () Application

(2) Java extension standard library org. W3C. Tidy. Tidy

(3) Use of URLs

Note:

The Org. W3C. tidy package used in this program is downloaded at http://sourceforge.net/projects/jtidy. Decompress the package and reference the tidy package in the build folder.

 

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.