Programming Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3

 

 

 

 

 

 

 

 

AddAttribute - Insert New Attribute in XML Node

Demonstrates adding an name=value attribute to an XML tag.

This example uses the XML sample file sample1.xml. The sample1.xml file contains this content:

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
#include <C_CkXml.h>

void ChilkatSample(void)
    {
    HCkXml xml;
    BOOL success;
    BOOL bFound;
    long numChildren;
    long i;

    xml = CkXml_Create();

    success = CkXml_LoadXmlFile(xml,"sample1.xml");
    if (success != TRUE) {
        printf("%s\n",CkXml_lastErrorText(xml));
        return;
    }

    //  Navigate to the "books" node:

    bFound = CkXml_FindChild2(xml,"books");
    if (bFound == FALSE) {
        printf("No books child found!\n");
        return;
    }

    numChildren = CkXml_getNumChildren(xml);

    for (i = 0; i <= numChildren - 1; i++) {

        //  Navigate to the Nth book (we'll assume success...)
        bFound = CkXml_GetChild2(xml,i);

        //  Display the book title:
        printf("%s\n",CkXml_getAttrValue(xml,"title"));

        //  Add a new integer attribute:
        //  Should never fail..
        success = CkXml_AddAttributeInt(xml,"bookId",i);

        //  Add a new unread="yes" attribute:
        success = CkXml_AddAttribute(xml,"unread","yes");

        //  Navigate back up to the parent:
        success = CkXml_GetParent2(xml);

    }

    //  Navigate back to the document root:
    CkXml_GetRoot2(xml);

    //  Save the updated document:
    success = CkXml_SaveXml(xml,"modified.xml");
    if (success != TRUE) {
        printf("%s\n",CkXml_lastErrorText(xml));
        return;
    }


    CkXml_Dispose(xml);

    }

Need a specific example? Send a request to support@chilkatsoft.com

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