Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Java Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
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)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Java) XMP API Helps Build the XML

The Chilkat XMP API is helpful in making it easier to build the XML that comprises XMP. If an XMP API feature does not exist to create the desired XML structure, then the Chilkat XML API can be used. The important thing to notice is that all XMP methods that modify XML pass the XML to be modified in the 1st argument. Thus, the XMP methods are really just helper methods to do common tasks in creating/editing the XML.

This example shows how to create a bag with a more complicated structure -- something that is not automatically provided by the XMP API, but can easily be done using the XML API.

Chilkat Java Downloads

Java Libs for Windows, MacOS, Linux, Alpine Linux, Solaris

Java Libs for Android

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkXmp xmp = new CkXmp();

    CkXml xml;

    // The first step is to create a new XMP document, which is nothing
    // more than XML.  The NewXmp method returns an XML document with
    // the standard XMP boilerplate.  
    xml = xmp.NewXmp();

    // Add some properties...
    boolean success = xmp.AddSimpleStr(xml,"Iptc4xmpCore:Chilkat","Blah blah");

    // Now create a Bag.
    CkStringArray sa = new CkStringArray();
    success = sa.Append("value_1");
    success = sa.Append("value_2");
    // ...

    // Notice the XML object is passed in the 1st argument.
    // The XMP method is really just a higher-level means to create XML
    // commonly needed for XMP.
    success = xmp.AddArray(xml,"bag","Iptc4xmpExt:LocationCreated",sa);

    // Let's examine the XML..
    System.out.println(xml.getXml());

    // the bag looks like this:

    //     <Iptc4xmpExt:LocationCreated>
    //         <rdf:Bag>
    //             <rdf:li>value_1</rdf:li>
    //             <rdf:li>value_2</rdf:li>
    //         </rdf:Bag>
    //     </Iptc4xmpExt:LocationCreated>

    // Let's say we really want this:

    //  <Iptc4xmpExt:LocationCreated>
    //    <rdf:Bag>
    //     <rdf:li rdf:parseType='Resource'>
    //      <Iptc4xmpExt:City>Ville création photo</Iptc4xmpExt:City>
    //      <Iptc4xmpExt:CountryName>Nom diu pays de la photo</Iptc4xmpExt:CountryName>
    //      <Iptc4xmpExt:ProvinceState>Département; Photo</Iptc4xmpExt:ProvinceState>
    //      <Iptc4xmpExt:Sublocation>Lieu création photo</Iptc4xmpExt:Sublocation>
    //     </rdf:li>
    //    </rdf:Bag>
    //   </Iptc4xmpExt:LocationCreated>

    // No problem...  Let's just fix it.

    CkXml x = xml.SearchForTag(xml,"Iptc4xmpExt:LocationCreated");

    // Assume it was found..
    // Move to the rdf:Bag node
    success = x.FirstChild2();

    // Discard the existing <rdf:il> values..
    x.RemoveAllChildren();

    // Build the new XML in its place..
    x.NewChild2("rdf:li","");
    success = x.AddAttribute("rdf:parseType","Resource");

    // Move to the "rdf:li" node.
    success = x.FirstChild2();
    x.NewChild2("Iptc4xmpExt:City","Ville création photo");
    x.NewChild2("Iptc4xmpExt:CountryName","Nom diu pays de la photo");
    x.NewChild2("Iptc4xmpExt:ProvinceState","Département; Photo");
    x.NewChild2("Iptc4xmpExt:Sublocation","Lieu création photo");

    // Let's create another bag item..
    // Move back up to the "rdf:Bag" node.
    success = x.GetParent2();

    x.NewChild2("rdf:li","");
    success = x.AddAttribute("rdf:parseType","Resource");

    // Move to the newly added "rdf:li" node, which is the 2nd child (index = 1)
    success = x.GetChild2(1);
    x.NewChild2("Iptc4xmpExt:City","2 Ville création photo");
    x.NewChild2("Iptc4xmpExt:CountryName","2 Nom diu pays de la photo");
    x.NewChild2("Iptc4xmpExt:ProvinceState","2 Département; Photo");
    x.NewChild2("Iptc4xmpExt:Sublocation","2 Lieu création photo");

    // Let's examine the XML now...
    System.out.println(xml.getXml());
  }
}

 

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