Generating Code to Create XMP XML
The Chilkat Xmp class provides the abililty to insert/update/remove/extract XMP metadata from JPEG and TIFF image files. In addition, the XMP API provides helper methods to make it easier to construct XML according to XMP specifications. These methods are usually sufficient, but may lack flexibility to create more complex XMP metadata. An alternative approach is to use Chilkat’s online code generate tools to generate the source code required to create a specific XMP sample. Assuming you have sample XMP metadata you wish to create, you may copy/paste the XML into the online tool at https://tools.chilkat.io/xmlCreate.cshtml
For example, if we have the following XMP:
<?xml version="1.0" encoding="utf-8"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:prefix0="http://ns.SomeApp.net/1.0/">
<prefix0:imageSettingsHash>443ed5e044e337ede86f4bbb48cf78f1</prefix0:imageSettingsHash>
</rdf:Description>
<rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>
<rdf:Alt xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:li xml:lang="x-default">regions added by SomeApp</rdf:li>
</rdf:Alt>
</dc:title>
</rdf:Description>
<rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:description>
<rdf:Alt xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:li xml:lang="x-default">regions added by SomeApp</rdf:li>
</rdf:Alt>
</dc:description>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:Iptc4xmpExt="http://iptc.org/std/Iptc4xmpExt/2008-02-29/">
<Iptc4xmpExt:PersonInImage>
<rdf:Bag>
<rdf:li>Laza</rdf:li>
<rdf:li>David</rdf:li>
<rdf:li>Jason</rdf:li>
<rdf:li>Pontus</rdf:li>
</rdf:Bag>
</Iptc4xmpExt:PersonInImage>
</rdf:Description>
<rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:mwg-rs="http://www.metadataworkinggroup.com/schemas/regions/" xmlns:stDim="http://ns.adobe.com/xap/1.0/sType/Dimensions#" xmlns:stArea="http://ns.adobe.com/xmp/sType/Area#">
<mwg-rs:Regions rdf:parseType="Resource">
<mwg-rs:AppliedToDimensions stDim:w="1000" stDim:h="667" stDim:unit="pixel"/>
<mwg-rs:RegionList>
<rdf:Bag>
<rdf:li>
<rdf:Description mwg-rs:Name="Laza" mwg-rs:Type="Face">
<mwg-rs:Area stArea:x="0.276" stArea:y="0.305847076461769" stArea:w="0.075" stArea:h="0.112443778110945" stArea:unit="normalized"/>
</rdf:Description>
</rdf:li>
<rdf:li>
<rdf:Description mwg-rs:Name="David" mwg-rs:Type="Face">
<mwg-rs:Area stArea:x="0.446" stArea:y="0.260869565217391" stArea:w="0.057" stArea:h="0.119940029985007" stArea:unit="normalized"/>
</rdf:Description>
</rdf:li>
<rdf:li>
<rdf:Description mwg-rs:Name="Jason" mwg-rs:Type="Face">
<mwg-rs:Area stArea:x="0.564" stArea:y="0.286356821589205" stArea:w="0.047" stArea:h="0.0974512743628186" stArea:unit="normalized"/>
</rdf:Description>
</rdf:li>
<rdf:li>
<rdf:Description mwg-rs:Name="Pontus" mwg-rs:Type="Face">
<mwg-rs:Area stArea:x="0.651" stArea:y="0.271364317841079" stArea:w="0.08" stArea:h="0.131934032983508" stArea:unit="normalized"/>
</rdf:Description>
</rdf:li>
</rdf:Bag>
</mwg-rs:RegionList>
</mwg-rs:Regions>
<xmp:CreatorTool>Some Tool</xmp:CreatorTool>
<xmp:ModifyDate>2019-11-13T13:20:23Z</xmp:ModifyDate>
<xmp:MetadataDate>2019-11-13T13:20:23Z</xmp:MetadataDate>
</rdf:Description>
<rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:MP="http://ns.microsoft.com/photo/1.2/" xmlns:MPRI="http://ns.microsoft.com/photo/1.2/t/RegionInfo#" xmlns:MPReg="http://ns.microsoft.com/photo/1.2/t/Region#">
<MP:RegionInfo rdf:parseType="Resource">
<MPRI:Regions>
<rdf:Bag>
<rdf:li rdf:parseType="Resource">
<MPReg:Rectangle>0.2385, 0.249625187406297, 0.075, 0.112443778110945</MPReg:Rectangle>
<MPReg:PersonDisplayName>Laza</MPReg:PersonDisplayName>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<MPReg:Rectangle>0.4175, 0.200899550224888, 0.057, 0.119940029985007</MPReg:Rectangle>
<MPReg:PersonDisplayName>David</MPReg:PersonDisplayName>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<MPReg:Rectangle>0.5405, 0.237631184407796, 0.047, 0.0974512743628186</MPReg:Rectangle>
<MPReg:PersonDisplayName>Jason</MPReg:PersonDisplayName>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<MPReg:Rectangle>0.611, 0.205397301349325, 0.08, 0.131934032983508</MPReg:Rectangle>
<MPReg:PersonDisplayName>Pontus</MPReg:PersonDisplayName>
</rdf:li>
</rdf:Bag>
</MPRI:Regions>
</MP:RegionInfo>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"/>
</rdf:RDF>
</x:xmpmeta>
The online tool generates the following C# code. (The tool provides options to generate many other programming languages.)
Chilkat.Xml xml = new Chilkat.Xml();
xml.Tag = "x:xmpmeta";
xml.AddAttribute("xmlns:x","adobe:ns:meta/");
xml.UpdateAttrAt("rdf:RDF",true,"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description",true,"rdf:about","uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b");
xml.UpdateAttrAt("rdf:RDF|rdf:Description",true,"xmlns:prefix0","http://ns.SomeApp.net/1.0/");
xml.UpdateChildContent("rdf:RDF|rdf:Description|prefix0:imageSettingsHash","443ed5e044e337ede86f4bbb48cf78f1");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[1]",true,"rdf:about","uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[1]",true,"xmlns:dc","http://purl.org/dc/elements/1.1/");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[1]|dc:title|rdf:Alt",true,"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[1]|dc:title|rdf:Alt|rdf:li",true,"xml:lang","x-default");
xml.UpdateChildContent("rdf:RDF|rdf:Description[1]|dc:title|rdf:Alt|rdf:li","regions added by SomeApp");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[2]",true,"rdf:about","uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[2]",true,"xmlns:dc","http://purl.org/dc/elements/1.1/");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[2]|dc:description|rdf:Alt",true,"xmlns:rdf","http://www.w3.org/1999/02/22-rdf-syntax-ns#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[2]|dc:description|rdf:Alt|rdf:li",true,"xml:lang","x-default");
xml.UpdateChildContent("rdf:RDF|rdf:Description[2]|dc:description|rdf:Alt|rdf:li","regions added by SomeApp");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[3]",true,"rdf:about","");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[3]",true,"xmlns:Iptc4xmpExt","http://iptc.org/std/Iptc4xmpExt/2008-02-29/");
xml.UpdateChildContent("rdf:RDF|rdf:Description[3]|Iptc4xmpExt:PersonInImage|rdf:Bag|rdf:li","Laza");
xml.UpdateChildContent("rdf:RDF|rdf:Description[3]|Iptc4xmpExt:PersonInImage|rdf:Bag|rdf:li[1]","David");
xml.UpdateChildContent("rdf:RDF|rdf:Description[3]|Iptc4xmpExt:PersonInImage|rdf:Bag|rdf:li[2]","Jason");
xml.UpdateChildContent("rdf:RDF|rdf:Description[3]|Iptc4xmpExt:PersonInImage|rdf:Bag|rdf:li[3]","Pontus");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]",true,"rdf:about","uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]",true,"xmlns:xmp","http://ns.adobe.com/xap/1.0/");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]",true,"xmlns:mwg-rs","http://www.metadataworkinggroup.com/schemas/regions/");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]",true,"xmlns:stDim","http://ns.adobe.com/xap/1.0/sType/Dimensions#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]",true,"xmlns:stArea","http://ns.adobe.com/xmp/sType/Area#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions",true,"rdf:parseType","Resource");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:AppliedToDimensions",true,"stDim:w","1000");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:AppliedToDimensions",true,"stDim:h","667");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:AppliedToDimensions",true,"stDim:unit","pixel");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description",true,"mwg-rs:Name","Laza");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description",true,"mwg-rs:Type","Face");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description|mwg-rs:Area",true,"stArea:x","0.276");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description|mwg-rs:Area",true,"stArea:y","0.305847076461769");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description|mwg-rs:Area",true,"stArea:w","0.075");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description|mwg-rs:Area",true,"stArea:h","0.112443778110945");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li|rdf:Description|mwg-rs:Area",true,"stArea:unit","normalized");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description",true,"mwg-rs:Name","David");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description",true,"mwg-rs:Type","Face");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description|mwg-rs:Area",true,"stArea:x","0.446");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description|mwg-rs:Area",true,"stArea:y","0.260869565217391");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description|mwg-rs:Area",true,"stArea:w","0.057");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description|mwg-rs:Area",true,"stArea:h","0.119940029985007");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[1]|rdf:Description|mwg-rs:Area",true,"stArea:unit","normalized");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description",true,"mwg-rs:Name","Jason");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description",true,"mwg-rs:Type","Face");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description|mwg-rs:Area",true,"stArea:x","0.564");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description|mwg-rs:Area",true,"stArea:y","0.286356821589205");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description|mwg-rs:Area",true,"stArea:w","0.047");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description|mwg-rs:Area",true,"stArea:h","0.0974512743628186");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[2]|rdf:Description|mwg-rs:Area",true,"stArea:unit","normalized");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description",true,"mwg-rs:Name","Pontus");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description",true,"mwg-rs:Type","Face");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description|mwg-rs:Area",true,"stArea:x","0.651");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description|mwg-rs:Area",true,"stArea:y","0.271364317841079");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description|mwg-rs:Area",true,"stArea:w","0.08");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description|mwg-rs:Area",true,"stArea:h","0.131934032983508");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[4]|mwg-rs:Regions|mwg-rs:RegionList|rdf:Bag|rdf:li[3]|rdf:Description|mwg-rs:Area",true,"stArea:unit","normalized");
xml.UpdateChildContent("rdf:RDF|rdf:Description[4]|xmp:CreatorTool","Some Tool");
xml.UpdateChildContent("rdf:RDF|rdf:Description[4]|xmp:ModifyDate","2019-11-13T13:20:23Z");
xml.UpdateChildContent("rdf:RDF|rdf:Description[4]|xmp:MetadataDate","2019-11-13T13:20:23Z");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]",true,"rdf:about","uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]",true,"xmlns:MP","http://ns.microsoft.com/photo/1.2/");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]",true,"xmlns:MPRI","http://ns.microsoft.com/photo/1.2/t/RegionInfo#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]",true,"xmlns:MPReg","http://ns.microsoft.com/photo/1.2/t/Region#");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]|MP:RegionInfo",true,"rdf:parseType","Resource");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li",true,"rdf:parseType","Resource");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li|MPReg:Rectangle","0.2385, 0.249625187406297, 0.075, 0.112443778110945");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li|MPReg:PersonDisplayName","Laza");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[1]",true,"rdf:parseType","Resource");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[1]|MPReg:Rectangle","0.4175, 0.200899550224888, 0.057, 0.119940029985007");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[1]|MPReg:PersonDisplayName","David");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[2]",true,"rdf:parseType","Resource");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[2]|MPReg:Rectangle","0.5405, 0.237631184407796, 0.047, 0.0974512743628186");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[2]|MPReg:PersonDisplayName","Jason");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[3]",true,"rdf:parseType","Resource");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[3]|MPReg:Rectangle","0.611, 0.205397301349325, 0.08, 0.131934032983508");
xml.UpdateChildContent("rdf:RDF|rdf:Description[5]|MP:RegionInfo|MPRI:Regions|rdf:Bag|rdf:li[3]|MPReg:PersonDisplayName","Pontus");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[6]",true,"rdf:about","");
xml.UpdateAttrAt("rdf:RDF|rdf:Description[6]",true,"xmlns:photoshop","http://ns.adobe.com/photoshop/1.0/");