Visual C++ Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Delphi ActiveXDelphi DLLVisual FoxProJavaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerShellPythonRubySQL ServerUnicode CUnicode C++Visual Basic 6.0VB.NETVBScript

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

Parse SOAP XML

Demonstrates how to parse SOAP XML.

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries
FreeBSD C++ Libraries
HP-UX C++ Libraries
BlackBerry QNX C++ Libraries
#include <CkXml.h>

void ChilkatSample(void)
    {
    bool success;
    CkXml xml;

    //  The Chilkat XML component is freeware.

    //  Load an XML document.
    //  This document may be downloaded at:
    //  http://www.chilkatsoft.com/testData/soap1.xml
    success = xml.LoadXmlFile("soap1.xml");
    if (success == false) {
        printf("%s\n",xml.lastErrorText());
        return;
    }

    //  The sample XML document parsed here is a prime example
    //  of how NOT to design your XML schema.  When designing
    //  XML, always keep in mind how a program might parse it.
    //  Poorly designed XML is a big pain-in-the-ass to parse.
    //  We'll show you a much better schema at the end of this
    //  example.

    //  Here's the XML we'll want to parse:

    //  <?xml version="1.0" encoding="utf-8"?><soap:Envelope
    //  xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    //  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    //  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    //  <soap:Body>
    //  <SendRequestResponse
    //  xmlns="http://merchantwarehouse.com/webservices/public/MerchantWareService1">
    //  <SendRequestResult>
    //  <Code>Approved</Code>
    //  <ProcessorData>[Response_Code][00][Response_Text][106857][Auth_Reference
    //  ][0016][Amount_Balance][205.78][Expiration_Date][012014][Trans_Date_Time
    //  ][012209000734][Card_Number][710001900593731][Transaction_ID][1]</ProcessorData>
    //  <Fields><Field>
    //  <Code>Unknown</Code><Value>1</Value>
    //  </Field>
    //  <Field>
    //  <Code>Message</Code><Value>106857</Value>
    //  </Field>
    //  <Field>
    //  <Code>AuthCodeResp</Code><Value>0016</Value>
    //  </Field>
    //  <Field>
    //  <Code>Balance</Code><Value>205.78</Value>
    //  </Field>
    //  </Fields>
    //  </SendRequestResult>
    //  </SendRequestResponse>
    //  </soap:Body>
    //  </soap:Envelope>

    //  The poor design choice in the above XML is to use the same tag over and over.
    //  For example "Field", "Code", and "Value".
    //  Here's a much much better design, and you'll see later how the parsing is so much simpler:
    // 
    //  ...
    //  <Fields>
    //  <Message>106857</Message>
    //  <AuthCodeResp>0016</AuthCodeResp>
    //  <Balance>205.78</Balance>
    //  </Fields>
    //  ...

    //  Notice it's much more compact.
    //  The other poor design choice is globbing all of that information in "ProcessorData".
    //  You can't use XML alone to parse the contents of that node -- you'll have to write
    //  some custom string parsing code for it...  (ughhh)
    // 

    //  OK... so let's parse this beast...
    //  We already have it loaded in an instance of the XML object.
    //  Drill down to the SendRequestResult node:
    xml.FirstChild2();
    xml.FirstChild2();
    xml.FirstChild2();

    //  Find the "Fields" node:
    CkXml *xmlFields = 0;
    xmlFields = xml.GetChildWithTag("Fields");

    //  Iterate over each field:
    long i;
    CkXml *xmlField = 0;
    long numChildren;
    numChildren = xmlFields->get_NumChildren();
    for (i = 0; i <= numChildren - 1; i++) {

        xmlField = xmlFields->GetChild(i);

        if (xmlField->HasChildWithTagAndContent("Code","Message") == true) {
            printf("Message: %s\n",xmlField->getChildContent("Value"));
        }

        //  Use the same logic for the other fields you want to capture...

        delete xmlField;
    }

    delete xmlFields;

    //  Here's the XML parsing code if the XML were designed like this:
    //  ...
    //  <Fields>
    //  <Unknown>1</Unknown>
    //  <Message>106857</Message>
    //  <AuthCodeResp>0016</AuthCodeResp>
    //  <Balance>205.78</Balance>
    //  </Fields>
    //  ...
    success = xml.LoadXmlFile("soap2.xml");
    if (success == false) {
        printf("%s\n",xml.lastErrorText());
        return;
    }

    xml.FirstChild2();
    xml.FirstChild2();
    xml.FirstChild2();

    //  Find the "Fields" node:
    xmlFields = xml.GetChildWithTag("Fields");

    //  Get each value:
    printf("-----\n");
    printf("Message: %s\n",xmlFields->getChildContent("Message"));
    printf("AuthCodeResp:%s\n",xmlFields->getChildContent("AuthCodeResp"));
    printf("Balance: %s\n",xmlFields->getChildContent("Balance"));

    delete xmlFields;
    }

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