Missing namespace when xmp is updated

Dear Aspose Support,

Our client encountered an issue where, after performing an XMP update, certain color profile namespaces are missing from the updated file’s XMP data. These missing namespaces are proprietary and do not belong to our client’s own XMP schema.

For your reference, I’ve attached the following files:

  • OriginalFile.docx and UpdatedXMP.docx – text versions of the XMP before and after the update.
  • MissingNamespaces.docx – a list of namespaces missing in the updated XMP. Take note that this was extracted from csv file so expect a different format but the important here is the namespace
    MissingNamespaces.docx (15.0 KB)

UpdatedXMP.docx (17.4 KB)

OrignalFile.docx (19.1 KB)

OriginalFile.jpg (174.0 KB)

UpdatedXMP.jpg (165.4 KB)

  • OriginalFile.jpg and UpdatedXMP.jpg – the image files from which the above XMP data was extracted.

Please review these attachments and advise on why the proprietary namespaces are being removed during the update.

Aspose.Imaging version 25.7.0

private void UpdateXmpMetadata(IUpdateXmpMetadataMediaAction action)
{
    using (var inputStream = System.IO.File.OpenRead(action.Path))
    using (var img = Image.Load(inputStream))
    {
        if ((_supportedTargetFormats.Contains(img.FileFormat) || Path.GetExtension(action.Path).ToLower() == ".jpg" || Path.GetExtension(action.Path).ToLower() == ".tif") && img is RasterImage && !String.IsNullOrEmpty(action.XmpMetadataMapping))
        {
            XDocument xmpMapping = XDocument.Parse(action.XmpMetadataMapping);

            // Getting the xmp metadata
            XmpPacketWrapper xmpData = ((RasterImage)img).XmpData;

            if (xmpData == null)
            {
                // Create xmp metadata if the image doesn't contains any xmp data.
                XmpHeaderPi xmpHeader = new XmpHeaderPi(Guid.NewGuid().ToString());
                XmpTrailerPi xmpTrailer = new XmpTrailerPi(true);
                XmpMeta xmpMeta = new XmpMeta();

                xmpData = new XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
                ((RasterImage)img).XmpData = xmpData;
            }

            foreach (var mapping in xmpMapping.Descendants("xmpMapping").Elements("add"))
            {
                // Get values from xmp metadata mapping
                var xmpNamespace = mapping.Attribute("namespace").Value;
                var xmpName = mapping.Attribute("name").Value;
                var xmpPrefix = mapping.Attribute("prefix").Value;
                var xmpValue = mapping.Value;

                if (xmpData.ContainsPackage(xmpNamespace))
                {
                    // Xmp namespace exists
                    foreach (var xmpPackage in xmpData.Packages)
                    {
                        if (xmpPackage.NamespaceUri.Trim().ToLower() == xmpNamespace.Trim())
                        {
                            if (xmpPackage.ContainsKey(xmpPackage.Prefix + ":" + xmpName))
                            {
                                // Update xmp value if the property exists
                                xmpPackage[(xmpPackage.Prefix + ":" + xmpName)] = xmpValue;
                            }
                            else
                            {
                                // Create new property if it not exists
                                xmpPackage.AddValue(xmpPackage.Prefix + ":" + xmpName, xmpValue);
                            }

                        }
                    }
                }
                else
                {
                    // Create xmp namespace and xmp property if namespace not exists
                    XmpBasicPackage xmp = new XmpBasicPackage(xmpPrefix, xmpNamespace);
                    xmp.AddValue(xmpPrefix + ":" + xmpName, xmpValue);
                    xmpData.AddPackage(xmp);
                }
            }
        }

        using (var outputStream = new MemoryStream())
        {
            img.Save(outputStream);
            using (var fileStream = System.IO.File.Create(action.OutputPath))
            {
                outputStream.Seek(0, System.IO.SeekOrigin.Begin);
                outputStream.CopyTo(fileStream);
            }
        }
    }
}```

@3stan

It appears that your client is encountering issues with missing proprietary color profile namespaces after updating the XMP data in the image files. This may be related to how the XMP metadata is being processed during the update.

In your code, you are checking if the XMP namespace already exists before adding or updating properties. If the proprietary namespaces are not being recognized or are being removed, consider the following steps:

  1. Namespace Handling: Verify that the proprietary namespaces are correctly defined and included in the XMP mapping. If they are not part of the xmpMapping, they will not be preserved.

  2. XMP Data Initialization: When creating new XMP data, ensure that all necessary namespaces are included from the outset. If the original image does not contain these namespaces, they must be added explicitly.

  3. Debugging: Implement logging to track which namespaces are being processed and whether the proprietary ones are being skipped or removed during the update.

Here’s a code snippet to help ensure that proprietary namespaces are preserved:

foreach (var mapping in xmpMapping.Descendants("xmpMapping").Elements("add"))
{
    var xmpNamespace = mapping.Attribute("namespace").Value;
    // Log the processing of the namespace
    Console.WriteLine($"Processing namespace: {xmpNamespace}");

    // Existing logic...
}

This logging will assist in identifying if the proprietary namespaces are being processed correctly. If they remain missing after these checks, consider reaching out to Aspose support with detailed logs for further assistance.

If you have any further questions or require more specific guidance, please feel free to ask!

@3stan Thank you for your interest in our product. We are investigating this issue and will inform you of the results as soon as possible.