Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PHP Extension Examples

ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
Facebook
FileAccess
Firebase
GMail REST API
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Sheets
Gzip
HTML-to-XML/Text
HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)

Java KeyStore (JKS)
Jira
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
PayPal
Peoplevox
QuickBooks
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
SugarCRM
Tar Archive
Twitter
Upload
VoiceBase
Walmart
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(PHP Extension) XML SearchForTag Method

Demonstrates the SearchForTag and SearchForTag2 methods.

The input XML, available at http://www.chilkatsoft.com/data/fruitSearch.xml, is this:

<root>
    <searchRoot>
        <fruit color="red">apple</fruit>
        <fruit color="green">pear</fruit>
        <veg color="orange">carrot</veg>
        <meat animal="cow">beef</meat>
        <xyz>
            <fruit color="blue">blueberry</fruit>
            <veg color="green">broccoli</veg>
        </xyz>
        <fruit color="purple">grape</fruit>
        <cheese color="yellow">cheddar</cheese>
    </searchRoot>
    <fruit color="red">strawberry</fruit>
    <fruit color="orange">peach</fruit>
</root>

Chilkat PHP Downloads

PHP Extension for Windows, Linux, MAC OS X,
Alpine Linux, Solaris, OpenBSD, FreeBSD,
and Linux armhf/aarch64

<?php

// The version number (9_5_0) should match version of the Chilkat extension used, omitting the micro-version number.
// For example, if using Chilkat v9.5.0.48, then include as shown here:
include("chilkat_9_5_0.php");

$xml = new CkXml();

//  The sample input XML is available at http://www.chilkatsoft.com/data/fruitSearch.xml
$success = $xml->LoadXmlFile('fruitSearch.xml');
if ($success != true) {
    print $xml->lastErrorText() . "\n";
    exit;
}

//  Search the sub-tree rooted at "searchRoot";
// xSearchRoot is a CkXml
$xSearchRoot = $xml->FindChild('searchRoot');

//  Search for all nodes having the tag "fruit";
// xBeginAfter is a CkXml
$xBeginAfter = $xml->GetSelf();
// xFound is a CkXml
$xFound = $xSearchRoot->SearchForTag($xBeginAfter,'fruit');
while (!(is_null($xFound))) {

    print $xFound->content() . "\n";

    // xBeginAfter is a CkXml
    $xBeginAfter = $xFound;
    // xFound is a CkXml
    $xFound = $xSearchRoot->SearchForTag($xBeginAfter,'fruit');
}

print '--------------------------' . "\n";

//  ---------------------------------------------------------------------------------
//  Now do the same, but instead use SearchForTag2
//  which updates the internal reference of the caller instead
//  of returning the found node.

// xBeginAfter is a CkXml
$xBeginAfter = $xSearchRoot->GetSelf();
// xSearch is a CkXml
$xSearch = $xSearchRoot->GetSelf();

$success = $xSearch->SearchForTag2($xBeginAfter,'fruit');
while ($success == true) {

    print $xSearch->content() . "\n";

    //  Copy the internal references so that the next search
    //  begins after the found node.
    $xBeginAfter->CopyRef($xSearch);
    $xSearch->CopyRef($xSearchRoot);

    $success = $xSearch->SearchForTag2($xBeginAfter,'fruit');
}


?>

 

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