# Photoshop plug-in, cannot modify XMP

**URL:** <https://forums.creativeclouddeveloper.com/t/photoshop-plug-in-cannot-modify-xmp/4496>\
**Category:** UXP Plugin API\
**Created:** [April 7, 2022, 4:02am UTC](https://forums.creativeclouddeveloper.com/t/photoshop-plug-in-cannot-modify-xmp/4496 "2022-04-07T04:02:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erpang](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/erpang/32/1994_2.png) [@erpang](https://forums.creativeclouddeveloper.com/u/erpang)\
**Post date:** [April 7, 2022, 4:02am UTC](https://forums.creativeclouddeveloper.com/t/photoshop-plug-in-cannot-modify-xmp/4496/1 "2022-04-07T04:02:53Z")

</div>

I used Batchplay to change the XMP of a document ，But there was no way to modify it successfully 😩

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/2/29aa4170b0ad51badbc60b76b511e94f5e9448ad.png)

---

<div class="post-metadata">

**Author:** ![simonhenke](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/simonhenke/32/957_2.png) [@simonhenke](https://forums.creativeclouddeveloper.com/u/simonhenke)\
**Post date:** [April 7, 2022, 6:48am UTC](https://forums.creativeclouddeveloper.com/t/photoshop-plug-in-cannot-modify-xmp/4496/2 "2022-04-07T06:48:37Z")

</div>

Did you try logging the `batchPlay` result or any errors in a try catch?  
Also, what’s the before/after of the Metadata and how does your xmpString look like?

---

<div class="post-metadata">

**Author:** ![erpang](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/erpang/32/1994_2.png) [@erpang](https://forums.creativeclouddeveloper.com/u/erpang)\
**Post date:** [April 7, 2022, 7:21am UTC](https://forums.creativeclouddeveloper.com/t/photoshop-plug-in-cannot-modify-xmp/4496/3 "2022-04-07T07:21:02Z")

</div>

```auto
import { convert} from 'xmlbuilder2';

 function getDocumentXMPMeta(docId,xmpString){
    const res = await batchPlay([ {
    _obj: 'get',
    _target: [
      {
        _ref: 'document',
        _id: documentID,
        _property: 'XMPMetadataAsUTF8',
      },
    ],
    _options: {
      dialogOptions: 'dontDisplay',
    },
  }], {
  });
  return res[0]?.XMPMetadataAsUTF8 || '';
}

 function setDocumentXMPMeta(docId,xmpString){
    const res = await batchPlay([ {
    _obj: 'set',
    _target: [
      {
        _ref: 'document',
        _id: docId,
        _property: 'XMPMetadataAsUTF8',
      },
    ],
    to: {
      _obj: 'document',
      XMPMetadataAsUTF8: xmpString,
    },
  }], {
  });
  return res[0]?.XMPMetadataAsUTF8 || '';
}

function setMetaXmp(docId){
  const xmpString = await getDocumentXMPMeta(docId);
  const obj = convert(xmpString, { format: 'object' });
  obj['x:xmpmeta']['rdf:RDF']['rdf:Description'][`@xmlns:${123}`] = 'test1';
  obj['x:xmpmeta']['rdf:RDF']['rdf:Description'][`${'xml'}:${456}`] = 'test2';
  const newXmpString = convert(obj, { format: 'xml' });
  await setDocumentXMPMeta(docId, newXmpString);
  const newString = await getDocumentXMPMeta(docId);
  console.log('oldXml',xmpString) //old xmp 
  console.log('newXml',newString) // new xmp
}

setMetaXmo(1); // execute

```

I’m transferring the XML：

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/a/acaed818f21e2a8c097d192a658828978d77b650.png)

But I got a new one：

 ![image](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/f/fa82e6238d48d0f14fabe93259976cfce0a7ef6c.png)

this fails to modify xmp 😭
