Java
Chilkat2 Java
Update a String Property in XMP
See more XMP Examples
Demonstrates how to open a JPG or TIF image file, access the XMP metadata, and update the value of a string property. (If the string property does not already exist, it is created.)Chilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Xml;
import com.chilkatsoft.chilkat2.Xmp;
public class ChilkatExample {
public static void main(String[] args) {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Xmp xmp = new Xmp();
// Load a JPG or TIF image file.
try {
xmp.loadAppFile("qa_data/xmp/AJ_123642_1511.tif");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Num embedded XMP docs: " + xmp.getNumEmbedded());
// This example assumes that XMP metadata is already present in the image file.
if (xmp.getNumEmbedded() == 0) {
System.out.println("No XMP metadata already exists..");
return;
}
// Get the XMP metadata.
Xml xml = xmp.getEmbedded(0);
// Show the XML:
System.out.println(xml.getXml());
// Update (overwrite) a string property.
xmp.addSimpleStr(xml, "NumberofTimes", "123");
try {
xmp.saveAppFile("qa_output/updated.tif");
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Success.");
}
}