Sample code for 30+ languages & platforms
PureBasic

Set a MIME Body from XML

See more MIME Examples

Demonstrates the Chilkat Mime.SetBodyFromXml method, which sets the body as XML, changes the media type to text/xml, and selects an appropriate transfer encoding. The only argument is the XML text.

Background: This produces an XML-typed part, common in machine-to-machine messaging — SOAP, AS2/EDI payloads, structured data attachments. Marking the content text/xml lets the receiver route and parse it correctly, and Chilkat picks a transfer encoding that preserves the XML across the transport.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkMime.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the Mime.SetBodyFromXml method, which sets the body as XML and changes the media
    ;  type to text/xml.  The only argument is the XML text.

    mime.i = CkMime::ckCreate()
    If mime.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    xml.s = "<note><to>Bob</to><from>Alice</from><body>Hello</body></note>"
    success = CkMime::ckSetBodyFromXml(mime,xml)
    If success = 0
        Debug CkMime::ckLastErrorText(mime)
        CkMime::ckDispose(mime)
        ProcedureReturn
    EndIf

    Debug "Content-Type: " + CkMime::ckContentType(mime)


    CkMime::ckDispose(mime)


    ProcedureReturn
EndProcedure