Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

XML Attributes problem

Return to Member Forum

  • Author
    Posts
    • #34224
      Simon Duckworth
      Participant

      I’m trying to use xml to apply metadata to figures in a workbook (there are maybe 40 figures). The figures are often multiple images, so my plan is to put a blank, non-printing frame around all the images which belong to a figure, tag it, and apply the metadata as individual attributes. I’ll then export the XML, and have an XML file containing the filename/path, and metadata.

      There are lots of attributes (30-ish) that I’ll need to add. Is there a way to create a ‘template’ of attributes that I can import to make this a bit easier, so when I edit each attribute, I’m only entering its value, not each attribute title each time.

      I’ve tried to duplicate the attributes, but the only option I have would be to delete them. Is there a way around this? Could I maybe import a DTD that contains attributes – is that possible?

    • #34226

      An interesting challenge — a mix of Proper User Interface, Ease of Use, Adjustability, and a side dish of How Does This Xml Stuff Actually Works.

      Try this script. You must fill in the tag name of your figures in the first variable, and fill the list ‘labels’ with the attribute names you want to add/change.
      The forum converts straight single and double quotes to curly ones, and you’ll have to change them back to straight before it can work. If you use the ESTK Editor to edit your scripts, you will see properly quoted text strings marked with a color, that might help.

      — 8< —- script follows below

      // xmlElementName contains your base XML tag
      xmlElementName = “Figure”;

      // attribute labels; add at will
      var labels = [
      “href”,
      “width”,
      “height”,
      “label3”,
      “etcetera”
      ];

      var values = new Array(labels.length);

      if (app.documents.length == 0)
      alert (“uh you didn’t open any document”);
      else if (!app.activeDocument.xmlTags.item(xmlElementName).isValid)
      alert (‘oh there seems to be no tag named “‘+xmlElementName+'”‘);
      else if (app.selection.length == 0)
      alert (“ah you forgot to select anything”);
      else if (app.selection.length > 1)
      alert (“please one at a time only!”);
      else if (app.selection[0].associatedXMLElement == null)
      alert (“yeah this object has no tag to begin with”);
      else if (app.selection[0].associatedXMLElement.markupTag.name != xmlElementName)
      alert (‘this object is tagged but with “‘+app.selection[0].associatedXMLElement.markupTag.name+'”, not with “‘+xmlElementName+'”‘);
      else
      {
      var obj = app.selection[0];
      var w = new Window(“dialog”, “Result”);
      for (i=0; i<labels.length; i++)
      {
      with (w.add(“group”))
      {
      add (“statictext”, undefined, labels[i]);
      values[i] = add (“edittext”, undefined, “”); values[i].characters = 30;

      prevVal = obj.associatedXMLElement.xmlAttributes.item(labels[i]);
      if (prevVal.isValid)
      values[i].text = obj.associatedXMLElement.xmlAttributes.item(labels[i]).value;
      }
      }
      with (w.add(“group”))
      {
      orientation = “row”;
      add (“button”, undefined, “OK”);
      add (“button”, undefined, “Cancel”);
      }
      if (w.show()==1)
      {
      for (i=0; i<labels.length; i++)
      {
      prevVal = obj.associatedXMLElement.xmlAttributes.item(labels[i]);
      if (prevVal.isValid)
      obj.associatedXMLElement.xmlAttributes.item(labels[i]).value = values[i].text;
      else
      obj.associatedXMLElement.xmlAttributes.add(labels[i], values[i].text);
      }
      }
      }

    • #34283
      Simon Duckworth
      Participant

      @Jongware – Wow. I’m blown away by this forum!

      Many many thanks for your comprehensive reply, I’m about to give this a go…

      Thanks again

Viewing 2 reply threads
  • You must be logged in to reply to this topic.
Forum Ads