We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Apparent error found when writing XmlBasicPackage

We’re using Aspose.Imaging to read/write metadata from various file types. We’re just upgrading from v18.11 to latest across the board.
We discovered that (for some reason that’s unclear) PSD support was moved from Aspose.Imaging to Aspose.PSD.
So I’m in process of massaging the area of our code that deals with PSDs to use the new assembly/classes.
I’ve discovered what seems to be a bug. Here’s a pertinent code block, migrated from what used to work with Aspose.Imaging:

var TMINamespace="http://mydomain.com/tmi/1.0/"
var TMINamespacePrefix = "tmi";
var TMIValue = "Metadata";
var metadata = "<metadata xmlns:m='Test.org' id='9113e379-595e-4f72-84c7-218adfc09311'></metadata>";
var metadataXml = "&lt;metadata xmlns:m=&quot;Test.org&quot; id=&quot;9113e379-595e-4f72-84c7-218adfc09311&quot;&gt;&lt;m:Classification value=&quot;Public&quot;&gt;&lt;alt&gt;Classification=Public&lt;/alt&gt;&lt;/m:Classification&gt;&lt;/metadata&gt;"

var stream = new FileStream(fileHandle, fileAccess);
stream.Seek(0, SeekOrigin.Begin);
var image = (Aspose.PSD.FileFormats.Psd.PsdImage)Aspose.PSD.Image.Load(stream);
var package = image.XmpData?.GetPackage(TMINamespace);
if (package == null)
	//metadataXml = System.Security.SecurityElement.Escape(metadata);

	package = new Aspose.PSD.Xmp.Schemas.XmpBaseSchema.XmpBasicPackage(TMINamespacePrefix, TMINamespace);
	package.AddValue(TMINamespacePrefix + ":" + TMIValue, metadataXml);

	image.XmpData = new Aspose.PSD.Xmp.XmpPacketWrapper();

var whatsStoredInFile = "<rdf:Description rdf:about=\"\"
        <tmi:Metadata>&amp;lt;metadata xmlns:m=&amp;quot;Test.org&amp;quot; id=&amp;quot;777811bd-5a6b-4305-874b-a5226114c33d&amp;quot;&amp;gt;&amp;lt;m:Classification value=&amp;quot;Public&amp;quot;&amp;gt;&amp;lt;alt&amp;gt;Classification=Public&amp;lt;/alt&amp;gt;&amp;lt;/m:Classification&amp;gt;&amp;lt;/metadata&amp;gt;</tmi:Metadata>

Notice that ‘<’ gets supplied as ‘<’ but when it’s written to the file (as checked in Photoshop itself) it ends up as ‘&lt;’.

When this is read back later via image.XmpData.GetPackage(TMINamespace).GetXmlValue() it won’t parse as valid XML.

While I can do some hackery on the read side to try to persuade this to work out using various string.Replace calls, that’s a bit unreliable. I’d prefer to see if I can get this logged as a bug and fixed.


Thank you for your report. We created the issue PSDNET-1231. Error on the writing XmlBasicPackage.