Hi Support,
I’m trying to add custom xmp tags to svg file metadata section.
Since I could not find any example code for this, I came up with the following code based on my research.
using (SvgImage svgImage = (SvgImage)Image.Load(inputPath))
{
if (svgImage.XmpData == null)
{
svgImage.XmpData = new Aspose.Imaging.Xmp.XmpPacketWrapper();
}
if (svgImage.XmpData.Meta == null)
{
svgImage.XmpData.Meta = new Aspose.Imaging.Xmp.XmpMeta();
}
svgImage.XmpData.Meta.AddAttribute($"xmp:MyCustomTag", "MyCustomTagValue");
svgImage.Save(outputPath, new SvgOptions());
}
This code adds my custom data to the metadata section as follows
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" id="body_1" width="1123" height="794">
<metadata>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="" xmp:MyCustomTag="MyCustomTagValue" >
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
</rdf:RDF>
</x:xmpmeta>
</metadata>
but breaks the file in the sense that image viewer apps won’t be able to load the image any more and display the following error message:
XML parse error: error code=201 (3) in (null):5:85: Namespace prefix xmp for MyCustomTag on xmpmeta is not defined
Please confirm if this is the way to go or else can you please provide a fully working example code?