Sample code for 30+ languages & platforms
Java

Load MIME from XML

See more MIME Examples

Demonstrates the Chilkat Mime.LoadXml method, which reconstructs a MIME tree from Chilkat's MIME XML. The only argument is the XML string.

Background: Chilkat can represent a MIME tree as XML — headers as elements, parameters as attributes — which is convenient for inspecting or editing structure with XML tools. This is the inverse of GetXml: it rebuilds the full MIME object from that representation. Invalid XML leaves the current object unchanged.

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;

    //  Demonstrates the Mime.LoadXml method, which reconstructs a MIME tree from Chilkat's MIME XML.
    //  The only argument is the XML string.

    CkMime mime = new CkMime();

    //  Chilkat MIME XML (as produced by GetXml).
    String xmlText = "<mime><contentType>text/plain</contentType><body>Hello.</body></mime>";

    success = mime.LoadXml(xmlText);
    if (success == false) {
        System.out.println(mime.lastErrorText());
        return;
        }

    System.out.println("Content-Type: " + mime.contentType());
  }
}