Sample code for 30+ languages & platforms
Java

Load XML from a Remote URL

Demonstrates how to load XML from a remote URL, such as https://www.chilkatsoft.com/hamlet.xml

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    //  This example assumes the Chilkat HTTP API to have been previously unlocked.
    //  See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    CkStringBuilder sbXml = new CkStringBuilder();

    //  Download the XML from the URL into sbXml
    success = http.QuickGetSb("https://www.chilkatsoft.com/hamlet.xml",sbXml);
    if (success == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    CkXml xml = new CkXml();

    //  Load the XML contained in sbXml
    success = xml.LoadSb(sbXml,true);
    if (success == false) {
        System.out.println(xml.lastErrorText());
        return;
        }

    System.out.println("Success.");
  }
}