1 Reply Latest reply on Mar 26, 2012 7:58 PM by Angusdog

    Error code for absent XML tag [JS, CS4-5]

    Angusdog Level 1

      Hi,

       

      I have a javascript to import XML and, along with various other operations, apply Indesign para and character styles to the XML tags.

       

      However, if a particular element doesn't appear (say for example <author>) in the XML, it generates an error as you'd expect.

       

      Is there an example of a javascript that catches those errors and imports the XML anyway, ignoring the absent XML tags? i.e. applying what para and character styles it can based on the XML in there?

       

      I have control over whether the XML coming in has empty XML tags and currently the empty XML tags are causing me issues (Tables within InDesign have additional empty rows for example).

       

      Thanks in advance,

       

      Simon.

        • 1. Re: Error code for absent XML tag [JS, CS4-5]
          Angusdog Level 1

          Answered it myself and for completion, I thought I'd post the answer.

           

          // Set up the styles to map tags to

          try

            {

          myDocument.xmlImportMaps.add(myDocument.xmlTags.item("body"),

          myDocument.paragraphStyles.item("body"));

          // There can be loads of these

            }

          catch(err)

            {

          // alert("Alert");

            }

           

          In my case, I thought about having an alert but I commented it out and it works as intended.