Help with script to read specific XMP metadata in an image
I'm creating a script for Photoshop to read a specific XMP metadata field in the file info of an image. I'm trying to specifically read the data that is located under the <dc:subject> area. I want to access the data under dc: subject > rdf: Bag > rdf: li. Here's an example (as it would appear in Raw Data field under an image's file info):
<dc:subject>
<rdf:Bag>
<rdf:li>****DATA I NEED HERE****</rdf:li>
</rdf:Bag>
</dc:subject>
So far, I have a script that can read XMP metadata, but I can't access that specific line of data I showed in the above example. I commented line 43 -- that needs to be updated so it can read into the dc: subject data. I can currently access certain pieces of data in an image file. For example, using this code, if i run xmp.getProperty(XMPConst.NS_DC, "subject") through the console, I get a result back, but it's not the data I need. I figured if I used the same logic as I applied to line 43, it would give me the results I am looking for. Any ideas on how to access the data I'm looking for?
function loadXMPLibrary() {
if (!ExternalObject.AdobeXMPScript) {
try {
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
} catch (e) {
alert("Can't load XMP Script Library")
return false;
}
}
return true;
}
function unloadXMPLibrary() {
if (ExternalObject.AdobeXMPScript) {
try {
ExternalObject.AdobeXMPScript.unloadXMPLibrary();
ExternalObject.AdobeXMPScript = undefined;
} catch (e) {
alert("Couldn't unload XMP Script Library")
}
}
}
function writeXMP(xmpData, xmpFile) {
xmpFile.open('w', 'Text');
xmpFile.encoding = 'UTF-8'
xmpFile.write(xmpData)
xmpFile.close()
}
function showXMPMetadata() {
var xmpLoad = loadXMPLibrary();
if (xmpLoad) {
var filepath = app.activeDocument.path + '/' + app.activeDocument.name;
var myFile = File(filepath);
xmpFile = new XMPFile(myFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
xmp = xmpFile.getXMP();
var myXmp = xmp.serialize();
xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY)
var skus = myXmp.getProperty(XMPConst.NS_RDF,"Bag"); //this needs to be updated
unloadXMPLibrary ();
return skus;
};
};
