Java
Chilkat2 Java
Load XML from a Remote URL
Demonstrates how to load XML from a remote URL, such as https://www.chilkatsoft.com/hamlet.xmlChilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.StringBuilder;
import com.chilkatsoft.chilkat2.Xml;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat HTTP API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
StringBuilder sbXml = new StringBuilder();
// Download the XML from the URL into sbXml
try {
http.quickGetSb("https://www.chilkatsoft.com/hamlet.xml", sbXml);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
Xml xml = new Xml();
// Load the XML contained in sbXml
try {
xml.loadSb(sbXml, true);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Success.");
}
}