2 Replies Latest reply on Apr 5, 2011 5:28 AM by JJMack

    JS CS3 search metadata

    John.Kordas Level 1

      Hi All,

       

      I'm sure someone here had posted this great code to parse a files metadata.

       

      function parseMetadata(xmp, tag) {
                              var re = new RegExp('<' + tag + '>(.+)</' + tag + '>');
                              var m = xmp.match(re);
                              if (!m) {
                              re = new RegExp("<[^:]+:" + tag + ">(.+)</[^:]+:" + tag + '>');
                              m = this.xmp.match(re);
                              }

                              return (m ? m[1] : '');
                              };

      var xmp = activeDocument.xmpMetadata.rawData;

      var myTag = parseMetadata(xmp, "rdf:li");

      The problem I'm having is I'm adding "TAG" to the to the keywords field, and as it's sitting in the tree as shown below I am only getting the first instance of the rdf:li tag which is <rdf:li>8</rdf:li>.

       

       

      <dc:subject>
                  <rdf:Bag>
                     <rdf:li>TAG</rdf:li>
                  </rdf:Bag>
               </dc:subject>

       

       

      I thought I might be able to use the exec() to return a true or false but i'm just getting undefiend in the script console.

       

      function parseMetadata(xmp, tag) {
                                  var re = new RegExp('<rdf:li>TAG</rdf:li>');
                                  return re.exec(xmp);

      }

       

      Any suggestions?

       

      Cheers.

        • 1. Re: JS CS3 search metadata
          Paul Riggott Level 6

          You can get the keywords with....

          alert(app.activeDocument.info.keywords);
          
          • 2. Re: JS CS3 search metadata
            JJMack Most Valuable Participant

            Parsing metadata is not as simple as that function   "rdf:li"  is used all over the place for list items there may be multiple elements in a  list item and more then one list item as well as more then one list. I just open a raw file that has no keywords and extracted the metatdata and looked for rdf:li found data like this:

                  <rdf:Description rdf:about=""

                        xmlns:dc="http://purl.org/dc/elements/1.1/">

                     <dc:creator>

                        <rdf:Seq>

                           <rdf:li>McAssey</rdf:li>

                        </rdf:Seq>

                     </dc:creator>

                     <dc:format>image/tiff</dc:format>

                  </rdf:Description>

             

                    <crs:ToneCurve>

                        <rdf:Seq>

                           <rdf:li>0, 0</rdf:li>

                           <rdf:li>255, 255</rdf:li>

                        </rdf:Seq>

                     </crs:ToneCurve>

             

                   <exif:ISOSpeedRatings>

                        <rdf:Seq>

                           <rdf:li>800</rdf:li>

                        </rdf:Seq>

                     </exif:ISOSpeedRatings>

             

            There are no keywords for this image but you parse function found my name..."McAssey"

            1 person found this helpful