Java
Chilkat2 Java
Download HTML from URL and Convert to XML
See more HTML-to-XML/Text Examples
Downloads an HTML page from a URL and converts it to XML.Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Global;
import com.chilkatsoft.chilkat2.HtmlToXml;
import com.chilkatsoft.chilkat2.Http;
public class ChilkatExample {
public static void main(String[] args) {
boolean success = false;
// Note: This example requires the Chilkat Bundle license.
// Any string argument automatically begins the 30-day trial.
Global glob = new Global();
try {
glob.unlockBundle("30-day trial");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Http http = new Http();
String html = "";
try {
html = http.quickGetStr("http://www.intel.com/");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
HtmlToXml htmlToXml = new HtmlToXml();
// Indicate the charset of the output XML we'll want.
htmlToXml.setXmlCharset("utf-8");
// Set the HTML:
htmlToXml.setHtml(html);
// Convert to XML:
String xml = htmlToXml.toXml();
// Save the XML to a file.
// Make sure your charset here matches the charset
// used for the XmlCharset property.
ERROR: Method not in Chilkat2 Java: HtmlToXml.WriteStringToFile
success = htmlToXml.ERROR();
System.out.println("Finished.");
}
}