Python Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Python Examples

Quick Start
Python Unicode
Python Byte Array
Python Certs
Python Email
Python Encryption
Python FTP
HTML-to-XML
Python HTTP
Python IMAP
Python MHT
Python MIME
Python RSA
Python S/MIME
Python Signatures
Python Socket
Python Spider
Python Tar
Python Upload
Python XML
Python XMP
Python Zip

More Examples...
String
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
SSH Key
SSH
SSH Tunnel
SFTP

Unreleased...
Bzip2
LZW
Bz2
Icon

 

 

 

 

 

 

 

Saving and Retrieving Data in XML

Saving and retrieving data in XML.

Download Chilkat Python Library

import sys
import chilkat


#  Create an XML file with data that will later be loaded and
#  accessed by field name:
xml = chilkat.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:

success = xml.SaveXml("emailData.xml")
if (success != True):
    print xml.lastErrorText()
    sys.exit()

xml2 = chilkat.CkXml()

#  Load the XML file:
success = xml2.LoadXmlFile("emailData.xml")
if (success != True):
    print xml2.lastErrorText()
    sys.exit()

#  Access the data by name
print xml2.getChildContent("from")
print xml2.getChildContent("toName")
print xml2.getChildContent("toAddr")
print xml2.getChildContent("subject")
print xml2.getChildContent("body")
print "------"

#  Let's say I want to load this into an email object:
email = chilkat.CkEmail()

email.put_From(xml2.getChildContent("from"))

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

print email.getMime()


 

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

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