3 Replies Latest reply on Dec 16, 2011 2:39 PM by TheDollarBill

    Adding new XMP Metadata into new illustrator document...

    TheDollarBill Level 1

      var app:Application = Illustrator.app;

      var doc:Document = app.activeDocument;

      var xmpString:String = doc.XMPString;

      var xmpMeta : XMPMeta = new XMPMeta(xmpString);                      

      var myNamespace : Namespace = new Namespace("test", "http://test.thisiscool");

      xmpMeta.myNamespace::stringName = "supercool";

      var tmp : String = xmpMeta.serialize();

      doc.XMPString = tmp;

      If I execute the above code block I end up with the following metadata inside the document:

      <rdf:Description rdf:about=""

                  xmlns:ns1="http://test.thisiscool">

               <ns1:stringName>supercool</ns1:stringName>

      </rdf:Description>

       

      Why is the prefix defaulted to "ns1" when I specified that it should be "test"?

      The documentation says you can register your own custom prefixes. But it doesn't say weather it's possible to do that programatically.  Is it?  If not, how is it done?:

      Prefixes are not stored in the data model, but only in namespace URIs. The parser collects the namespace prefixes, to be used when the same XMPMeta object is serialized after modification. For the Adobe standard namespaces, defined in the XMP Specification: Part 2, Standard Schemas, the default namespaces are stored in a global namespace registry of the library. You can also register custom prefixes for your own namespaces; if the serializer does not find a registered prefix for a certain namespace, it generates prefixes of the form "ns1", "ns2" and so on.

        • 1. Re: Adding new XMP Metadata into new illustrator document...
          lesavage Adobe Employee

          Try the following to register the namespace pair:

           

          var xmpMeta:XMPMeta = new XMPMeta(xmpString);

          var myNamespace:Namespace = new Namespace("test", "http://test.thiscool");

          if (xmpMeta.getNamespace(myNamespace.prefix) != myNamespace.uri)

          {

            myNamespace = xmpMeta.registerNamespace(myNamespace.uri, myNamespace.prefix, true);

          }

           

          Kind regards,

          Lea

          • 2. Re: Adding new XMP Metadata into new illustrator document...
            TheDollarBill Level 1

            Okay.  I'm embarassed.  I can't believe I missed that registerNamespace method in the XMPMeta class documentation.  Thanks you so much.  Worked like a charm.

            -Bill

            • 3. Re: Adding new XMP Metadata into new illustrator document...
              TheDollarBill Level 1

              Okay, I'm now having a bit of an issue when testing to see if a Namespace exists in a given document:

               

                var topDoc:Document = myApp.activeDocument;

                var topXmpString:String = topDoc.XMPString;

                var topXmpMeta:XMPMeta = new XMPMeta(topXmpString);

                var topNamespace:Namespace = new Namespace(tag, schemaName);

                if (topXmpMeta.getNamespace(topNamespace.prefix) == topNamespace.uri) //if xmp schema already exists

              { //doo stuff }

               

              So, for some reason,

              When I save xmp to one document using a newly created and registered namespace,

              THEN create a new document which does NOT contain that namespace...

              if I run the test in the above codeblock,

              the namespace is found as a registered namespace even though no references to the namespace nor any properties of the namespace can be found in that new document's raw XMP string. 

              What gives?  And is there another way to test if there are any properties of a given namespace in a document's XMP info?