1 Reply Latest reply on Apr 12, 2011 11:55 PM by John Hawkinson

    textFrame, select paragraph, delete everything else

    xmlapi Level 1

      I have a main textframe on each page.


      I want to select the "description" paragraph and then delete all other text in the page and then export just this page as a PDF.


      I've figured out how to export the PDF but how do I selected the description paragraph but deleted everything else? The description paragraph is tagged with the xml tag description.

        • 1. Re: textFrame, select paragraph, delete everything else
          John Hawkinson Level 5

          You can either (1) recurse through the XML tree starting at the root of the document, or (2) you can iterate over the textframes and take their .associatedXMLElement. Then you have to delete the text that is not in a <description/> elements.


          When I tag an individual paragraph in a textframe on a page, I get this XML structure:


          <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
           <description>The rain in 1spain
           Falls mainly on the plain2


          This is a bit annoying since it's not just a matter of removing elements. If you were to remove the <Story/> then the <description/> would go away along with it. Assuming you only have one <description/> inside each story, the following should be sufficient; please note that you will lose the <description/> tag along the way as a result of doing it this way:


          var i, tf;
          for (i=0; i<=app.activeDocument.textFrames.length; i++) {
              tf = app.activeDocument.textFrames[i];
              tf.contents = tf.associatedXMLElement.


          This extracts the "description" node of each textFrame and sets the textFrame contents to the contents of that node, throwing away all other content.