Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMime
    String sXml
    String sTemp1

    Move False To iSuccess

    //  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.

    Get Create (RefClass(cComChilkatMime)) To hoMime
    If (Not(IsComObjectCreated(hoMime))) Begin
        Send CreateComObject of hoMime
    End

    Move "<note><to>Bob</to><from>Alice</from><body>Hello</body></note>" To sXml
    Get ComSetBodyFromXml Of hoMime sXml To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMime To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComContentType Of hoMime To sTemp1
    Showln "Content-Type: " sTemp1


End_Procedure