Chilkat Examples

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

C++ Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Cloud Storage
Google Drive
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc

IMAP
JSON
Java KeyStore (JKS)
Jwt
MHT / HTML Email
MIME
NTLM
OAuth1
OAuth2
OpenSSL
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
Socket/SSL/TLS
Spider
Stream
Tar Archive
Twitter
XML
XMP
Xero
Zip
curl

 

 

 

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