Table of Contents

Class XmpStruct

Namespace
Egami.Metadata
Assembly
Egami.dll

An XMP structure: named fields, each a simple value (string), an XmpArray or another XmpStruct, such as Iptc4xmpCore:CreatorContactInfo. XmpData holds its top-level properties the same way.

public class XmpStruct
Inheritance
XmpStruct
Derived
Inherited Members

Examples

XmpData xmp = new()
{
    Title = "Harbour at dawn",
    Creators = ["A. Photographer"],
    Keywords = ["harbour", "Bergen"],
    Rating = 4,
};

// Any property, by namespace URI and local name; structures and arrays nest.
XmpStruct contact = new();
contact.Set(new XmpName(XmpNamespaces.IptcCore, "CiEmailWork"), "photo@example.com");
xmp.Set(new XmpName(XmpNamespaces.IptcCore, "CreatorContactInfo"), contact);
if (xmp.TryGet(new XmpName(XmpNamespaces.DublinCore, "title"), out object? title) && title is XmpArray languages)
{
    languages.SetLanguage("nb-NO", "Havn ved daggry");
}

ReadOnlyMemory<byte> packet = xmp.ToBytes();   // canonical RDF/XML with padding

Constructors

XmpStruct()

Creates an empty structure.

public XmpStruct()

Properties

Count

Gets the number of fields.

public int Count { get; }

Property Value

int

Names

Gets the names of the fields, in order.

public IReadOnlyList<XmpName> Names { get; }

Property Value

IReadOnlyList<XmpName>

Methods

Copy()

Returns an independent copy.

public XmpStruct Copy()

Returns

XmpStruct

The copy.

GetText(XmpName)

Returns a field as text: a simple value as it is, a language alternative's x-default item (else its first), an ordered or unordered array's first item; null when there is no text to give.

public string? GetText(XmpName name)

Parameters

name XmpName

The field.

Returns

string

The text.

Remove(XmpName)

Removes a field.

public bool Remove(XmpName name)

Parameters

name XmpName

The field.

Returns

bool

Whether it was there.

Set(XmpName, XmpArray)

Sets a field to an array, replacing what was there. An array that already belongs elsewhere is copied.

public void Set(XmpName name, XmpArray value)

Parameters

name XmpName

The field.

value XmpArray

The array.

Set(XmpName, XmpStruct)

Sets a field to a structure, replacing what was there. A structure that already belongs elsewhere is copied.

public void Set(XmpName name, XmpStruct value)

Parameters

name XmpName

The field.

value XmpStruct

The structure.

Set(XmpName, string)

Sets a field to a simple value, replacing what was there.

public void Set(XmpName name, string value)

Parameters

name XmpName

The field.

value string

The text.

TryGet(XmpName, out object?)

Returns a field's value: a string, an XmpArray or an XmpStruct.

public bool TryGet(XmpName name, out object? value)

Parameters

name XmpName

The field.

value object

The value, or null.

Returns

bool

Whether the field is there.

TryGetDate(XmpName, out DateTimeOffset)

Returns a simple value written as an XMP date (ISO 8601: YYYY, YYYY-MM, YYYY-MM-DD, then optionally Thh:mm, :ss and fractions, and a zone); a date with no zone is taken as UTC.

public bool TryGetDate(XmpName name, out DateTimeOffset value)

Parameters

name XmpName

The field.

value DateTimeOffset

The date.

Returns

bool

Whether the field is a date.

TryGetInt(XmpName, out long)

Returns a simple value as an integer, if it is one.

public bool TryGetInt(XmpName name, out long value)

Parameters

name XmpName

The field.

value long

The integer.

Returns

bool

Whether the field is an integer.

TryGetRational(XmpName, out double)

Returns a simple value written as a rational ("28/10") or a decimal number ("2.8"), as a number.

public bool TryGetRational(XmpName name, out double value)

Parameters

name XmpName

The field.

value double

The number.

Returns

bool

Whether the field is a number.