Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.js

C++ Examples

Async
Certificates
ECC
Email Object
Encryption
FTP
HTML-to-XML/Text
Gzip
HTTP
IMAP
JSON
Jwt
MHT / HTML Email
PEM
PFX/P12
Java KeyStore (JKS)
POP3
RSA Encryption
MIME
REST
SCP
SMTP
Socket/SSL/TLS
SSH Key
SSH
SSH Tunnel
SFTP
Stream
Tar Archive
XML
XMP
Zip

More Examples...
OpenSSL
Google APIs
Google Cloud Storage
Azure Cloud Storage
Amazon S3 (new)
Google Drive
Dropbox
Firebase
ASN.1
PRNG
Amazon S3
Bounced Email
CSV
Diffie-Hellman
DKIM / DomainKey
DSA
NTLM
QuickBooks
Spider
Digital Signatures

 

 

 

 

 

 

 

(C++) Parse SOAP XML Response

Code to parse a SOAP XML response.

This is the SOAP response parsed by the code below:





  
    34.5
  

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS/Heroku C/C++

MAC OS X C/C++

C++ Builder

Solaris C/C++

iOS C/C++

Android C/C++

Raspberry Pi C/C++

Windows Mobile 5.0/Pocket PC 2003

ARM Embedded Linux C/C++

PowerLinux C/C++

FreeBSD C/C++

MinGW C/C++

#include <CkXml.h>

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

    //  Load the XML object with the SOAP response.
    //  The XML may be loaded from a file by calling
    //  LoadXmlFile, or directly from a string by calling
    //  LoadXml.
    success = xml.LoadXmlFile("soapResponse.xml");
    if (success != true) {
        std::cout << xml.lastErrorText() << "\r\n";
        return;
    }

    //  The quickest way to get a piece of data is w/ the
    //  ChilkatPath method.
    //  To get the content of the m:Price node:
    const char *strPrice = 0;
    strPrice = xml.chilkatPath("soap:Body|m:GetStockPriceResponse|m:Price|*");
    std::cout << "Price = " << strPrice << "\r\n";

    //  ------------------------------------
    //  Another way of doing it:

    //  Another way to get it is to navigate to the node.
    //  Navigate to soap:Body
    xml.FirstChild2();

    //  Navigate to m:GetStockPriceResponse
    //  You may call FirstChild2, or you may call GetChildWithTag2
    //  to get the Nth direct child having a given tag.
    //  In this case, get the 1st direct child having the tag
    //  "m:GetStockPriceResponse"
    //  (Indexing begins at 0, so the 1st occurance is at index 0.)
    bFound = xml.GetNthChildWithTag2("m:GetStockPriceResponse",0);
    if (bFound != true) {
        std::cout << "Did not find m:GetStockPriceResponse node." << "\r\n";
        return;
    }

    //  One more to go..
    bFound = xml.GetNthChildWithTag2("m:Price",0);
    if (bFound != true) {
        std::cout << "Did not find m:Price node." << "\r\n";
        return;
    }

    //  The content of the "m:Price" node is "34.5"
    strPrice = xml.content();
    std::cout << "Price = " << strPrice << "\r\n";

    //  Restore the xml object's internal reference to the root
    //  of the XML document:
    xml.GetRoot2();

    //  ------------------------------------
    //  Another way of doing it:

    //  If you know that the node w/ the content you want to
    //  extract is uniquely tagged (i.e. no other node has the same
    //  tag), then search for the node having the tag:
    bFound = xml.SearchForTag2(xml,"m:Price");
    if (bFound != true) {
        //  Not found...
        return;
    }

    //  The content of the "m:Price" node is "34.5"
    strPrice = xml.content();
    std::cout << "Price = " << strPrice << "\r\n";

    //  Restore the xml object's internal reference to the root
    //  of the XML document:
    xml.GetRoot2();

    //  ------------------------------------
    //  Another way of doing it:

    //  Again, assuming there is only a single node with the
    //  tag to be fetched:
    strPrice = xml.accumulateTagContent("m:Price","");
    std::cout << "Price = " << strPrice << "\r\n";

    //  There are many other possible ways of doing the same thing...

    }

 

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