xml| translation in the first article written by Java expert Michael Geisler for Builder Australia, he showed readers how to use Jtidy to convert HTML files into XML.
The most important thing about Java is that there are many extended standard libraries that can be part of a standard platform, and there is a lot of support for XML in those libraries. However, for some specific needs, there may not be direct support in the standard library.
In fact, you have two choices:
To build something entirely by yourself. This is generally painful and time-consuming.
Go to the "community" and see if someone has the same problem (which is very likely to happen) and see if he is happy to share his results with you.
For this case, SourceForge has a very useful small project, called Jtidy. The Jtidy Web site is located in http://sourceforge.net/projects/jtidy/.
Jtidy provides HTML syntax checking and HTML "pretty printing (pretty print)", but for you it also allows you to use an HTML file as input and then convert it into XML. Jtidy reads the input file, and if it finds any closed tags that do not match or omit, the tags are corrected and a well-formed XML document is finally exported.
As you can see from the example code below, the use of jtidy is fairly straightforward. Simply set the Jtidy instance to output XML, provide an input URL, output files and error files, and then start the conversion process.
public static void Main (string[] args) {
/*
* Parameters are:
* URL of HTML file
* Filename of output file
* Filename of error file
*/
Testhtml2xml t = new Testhtml2xml (Args[0], args[1], args[2]);
T.convert ();
}
}
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.