Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Email Object
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Saving and Retrieving Data in XML

Saving and retrieving data in XML.

Download Chilkat Java Library

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[])
  {

    //  Create an XML file with data that will later be loaded and
    //  accessed by field name:
    CkXml xml = new CkXml();
    xml.put_Tag("emailData");

    xml.NewChild2("from","admin@chilkatsoft.com");
    xml.NewChild2("toName","Chilkat Support");
    xml.NewChild2("toAddr","support@chilkatsoft.com");
    xml.NewChild2("subject","This is a test");
    xml.NewChild2("body","This is an email body");

    //  Save the XML:
    boolean success;
    success = xml.SaveXml("emailData.xml");
    if (success != true) {
        System.out.println(xml.lastErrorText());
        return;
    }

    CkXml xml2 = new CkXml();

    //  Load the XML file:
    success = xml2.LoadXmlFile("emailData.xml");
    if (success != true) {
        System.out.println(xml2.lastErrorText());
        return;
    }

    //  Access the data by name
    System.out.println(xml2.getChildContent("from"));
    System.out.println(xml2.getChildContent("toName"));
    System.out.println(xml2.getChildContent("toAddr"));
    System.out.println(xml2.getChildContent("subject"));
    System.out.println(xml2.getChildContent("body"));
    System.out.println("------");

    //  Let's say I want to load this into an email object:
    CkEmail email = new CkEmail();

    email.put_From(xml2.getChildContent("from"));
    String toName;
    String toAddr;
    toName = xml2.getChildContent("toName");
    toAddr = xml2.getChildContent("toAddr");
    email.AddTo(toName,toAddr);
    email.put_Subject(xml2.getChildContent("subject"));
    email.put_Body(xml2.getChildContent("body"));

    System.out.println(email.getMime());


  }
}

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.