# Document XMP metadata

**URL:** <https://forums.creativeclouddeveloper.com/t/document-xmp-metadata/3486>\
**Category:** Photoshop\
**Created:** [August 10, 2021, 7:12pm UTC](https://forums.creativeclouddeveloper.com/t/document-xmp-metadata/3486 "2021-08-10T19:12:08Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![DavideBarranca](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/davidebarranca/32/1523_2.png) [@DavideBarranca](https://forums.creativeclouddeveloper.com/u/DavideBarranca)\
**Post date:** [August 11, 2021, 7:50pm UTC](https://forums.creativeclouddeveloper.com/t/document-xmp-metadata/3486/3 "2021-08-11T19:50:16Z")

</div>

Solved 🍷  
I had to use a different XML library called `xmlbuilder2`.

```auto
const { convert } = require('xmlbuilder2');

// GETTER
// -------------------------------------------------
// <rdf:Description xmlns:undavide="http://davidebarranca.com/notes/" etc...>
// <undavide:Notes>someValue</undavide:Notes>
// -------------------------------------------------
// key: Notes
// prefix: undavide
// namespace: http://davidebarranca.com/notes/

export const getDocumentMetadata = ({ key, prefix = 'undavide', namespace = 'http://davidebarranca.com/notes/' }) => {
  const xmpString = getDocumentXMP();
  const obj = convert(xmpString, { format: "object" });
  return obj["x:xmpmeta"]['rdf:RDF']['rdf:Description'][`${prefix}:${key}`] || "nothing";
}

// SETTER
// -------------------------------------------------
// <rdf:Description xmlns:undavide="http://davidebarranca.com/notes/" etc...>
// <undavide:Notes>someValue</undavide:Notes>
// -------------------------------------------------
// key: Notes
// value: someValue
// prefix: undavide
// namespace: http://davidebarranca.com/notes/

export const setDocumentMetadata = async ({ key, value, prefix = 'undavide', namespace = 'http://davidebarranca.com/notes/' }) => {
  const xmpString = getDocumentXMP();
  const obj = convert(xmpString, { format: "object" });
  obj["x:xmpmeta"]['rdf:RDF']['rdf:Description'][`@xmlns:${prefix}`] = namespace;
  obj["x:xmpmeta"]['rdf:RDF']['rdf:Description'][`${prefix}:${key}`] = value;
  const newXmpString = convert(obj, {format: "xml"})
  await setDocumentXMP(newXmpString);
}

```

Might need a bit of extra testing for edge cases. What fun XML is, who would have thought 🙂  
If you run the prerelease version of PS see my post in the forums there for details on the BatchPlay call.

Davide

---

_[View the full topic](https://forums.creativeclouddeveloper.com/t/document-xmp-metadata/3486)._
