Sample code for 30+ languages & platforms
Rust

XMP Array Property - Bag, Seq, or Alt

See more XMP Examples

How to insert or update an XMP array property (bag, seq, or alt).

Chilkat Rust Downloads

Rust

// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let xmp = chilkat::Xmp::new();

// Load a JPG or TIF image file.
// Sample JPG's with XMP metadata may be found at:
// http://www.chilkatsoft.com/testData/xmp/sample1.jpg
// http://www.chilkatsoft.com/testData/xmp/sample2.jpg
// http://www.chilkatsoft.com/testData/xmp/sample3.jpg
if xmp.load_app_file("sample1.jpg").is_err() {
    println!("{}", xmp.last_error_text());
    return;
}

println!("Num embedded XMP docs: {}", xmp.num_embedded());

// Assuming there is at least one, get the 1st.
// (There is typically never more than one, but theoretically it's possible.)
if let Ok(xml) = xmp.get_embedded(0) {

    // Create an object to hold one or more string values.
    let sa = chilkat::StringArray::new();
    let _ = sa.append("value_1").is_ok();
    let _ = sa.append("value_2").is_ok();
    // ...

    if xmp.add_array(&xml, "bag", "Iptc4xmpCore:Chilkat", &sa).is_err() {
        println!("{}", xmp.last_error_text());
    } else {
        // Save the JPG.
        if xmp.save_app_file("modified.jpg").is_err() {
            println!("{}", xmp.last_error_text());
        }

    }

} else {
    println!("{}", xmp.last_error_text());
}