[AS CS5.5] Bad Perfomance: sequentially using DOM to get references

Hi guys,
The issue
I'm having terrible performance problems when using a complex script I wrote.
The script
I need to make some special comparisons between found text and the texts in that page.
My script is written in Flash Builder 4, using the CS_SDK (without Extension Builder)
In short, my script has a class that performs the following tasks:
1. Finds texts that meet some criteria (by using Document.findText() method) and stores the Array of texts result in an array.
2. Traverses the Array of found texts and, for each one of them:
a. Finds a reference to the page where that text is. Something like (within a for loop, with iFoundText as the indexing var):
var currentParentPage     :Page     =
     foundText[iFoundText].parentStory.textContainers[0].parentPage;
b. Finds all the page items in that page. The code goes something like this:
var myPageItems      :Object     =
     currentParentPage.allPageItems;
c. If the PageItem is a TextFrame, then make the 'special comparison', word by word.
if (currentPageItem is TextFrame)
          var allTheWords     :Words =
               currentPageItem.words
          for (var iWord:int = 0 ; iWord < allTheWords.length ; iWord++)
               //Code to perform comparison and related operations...
It seems to work OK, when allowing to perform the script for he first three occurrences (although very slow, say some 12 seconds for this).
So, what's the problem?
What happens when I run it with more load:
When I run the script for all the occurrences (I know that the number is around 100), the application halts, an stops responding. After 10 min it doesn't work anymore.
What the documentation says:
I found a document called "FEATURE DEVELOPMENT WITH SCRIPTING - Adobe CS5" (link), where it gives this recommendation:
Performance techniques
Minimize access to InDesign DOM
Querying the InDesign DOM may be the main performance bottleneck for your script. A considerable amount of time typically is spent resolving object references, because InDesign does not hand out pointers to objects but rather uses references that need to be resolved every time they are used. Here are some techniques to alleviate this problem:
z Reduce the number of calls to the scripting DOM.
z Store and reuse resolved references in variables wherever possible.
z Use everyItem() to fetch and cache data of a collection object all at once, instead of querying the properties with separate calls.
But I don't know how to not query InDesign's DOM every time...
So. I understand that calling InDesign's DOM is bad for the script's performance, but I really don't know how could I avoid querying it for getting references to parent objects, or any other item.
I have two questions
1. If I have a variable stored in my AS script, for example:
var anyTextItem:com.adobe.indesign.Text
When I call a property or a method of that variable... Am I querying InDesign's DOM? (in other words, the variables' content is passed as a reference?)
2. How do I query the DOM less times?
For example:
Problem: I constantly need to know what's the parent page of a found text, and then get the array of page items, and then, the array of words of every page item that is a textframe.
How could I query the DOM once and then play with the stored variables instead of repetitively querying the DOM?
Because, even if I have the variable stored, say "anyTextItem:Text", and I also have all the document's TextFrames stored in other variable (say "var allTextFrames:TextFrames"), I would still need to call "anyTextItem.parentTextFrame" to get a reference to the containing textFrame, and that would mean "querying InDesign's DOM".
I would appreciate if anybody understands how to solve this.
Thanks you, guys !

Harbs,
Thank you very much for your answer. You're very knowledgeable about InDesign DOM.
Your message gives me a better understanding of how objects are managed between a scripting environment and the DOM. I still have some questions, though...
b.
I will change the call to 'allPageItems' to 'page.textFrames.everyItem().getElements()'. It makes much more sense.
Now, quick question:
What do you use 'getElements()' for?
What's the diference between calling 'page.textFrames.everyItem().getElements()' and 'page.textFrames.everyItem()'?
c.
OK. I kinda got it. But, I have questions here too.
For me, it's been quite tricky to understand indexes and references for InDesign DOM objects.
Let's say that I have stored a Story's words object in my script. Something like:
var currentWords     :Words = currentStory.words;
And then, I go through a TextFrame that contains part of that Story, and find one word that meets my criteria. So I get:
var foundWord        :Word = (... Somehow I got a reference to this ...);
Is it there a way to easily find that word (by index) in the 'currentWords' object? (maybe using index or id...) The problem is that I've found that sometimes the indexes don't match (i. e. if I call "foundWord.index", its index can be way larger than the parentStory.words.length, for example, I got foundWord.index=942, whereas foundWord.parentStory.length=742).
And, as a consequence, I'm using long workarounds to find the word within that collection (and I guess you'd scold me for this one; now I think that might be a serious performance killer, because I'm reconstructing the 'words' collection over and over again :S)
Thanks again to both of you (@Harbs and @Andrés), you've been very kind and helpful.

Similar Messages

  • Use DOM to get the element value of XML document?

    I can not to use the method getNodeValue to get the element value of XML document. How can I do for it?
    For example, for element
    <address>125 Smith Avenue</address>
    how to get the value "125 Smith Avenue" by using DOM?
    Thanks

    Thanks for all of you.
    The code indicates that I need to get the node by tag name. If I do not know the distribution of the elements and want to traverse all nodes. If the node contains value, I retrieve the value. How to implement the general case.
    For example, my XML file represent a directory hierarchy and looks like
    <root>
    <usr>
    <user>user1
    <file>file1</file>
    <file>file2</file>
    </user>
    <user>user2
    <file>file1</file>
    <file>file2</file>
    <file>file3</file>
    <file>file4</file>
    </user>
    </usr>
    </root>

  • How to parse using DOM parser:

    <employee>
         <name>phaneendra</name>
         <age>21</age>
         <company>ABC</company>
         <Authorization>
              <ID>21<ID>
              <Role>Normal</Role>
         </Authorization>
    </employee>
    I am using DOM Parser.Using that parser how can i wil get the <Authorization> node value as
    <Authorization>
         <ID>21<ID>
         <Role>Normal</Role>
    </Authorization>
    thanks in advance

    Since you seem new to using DOM, I'll first give a word of advice.
    Get very familiar with the JavaDocs for things like Document, Element, Node and Attribute. There is much wisdom in those files, especially in the table near the top of the Node interface. Pay particular attention to the meaning of nodeValue for various types on content.
    Using DOM, you get a Document.
    From a Document, you can use the getDocumentElement to get the root element (in your case, the one with a name of "employee").
    From an Element, to get to a child Element with a specific name, use getElementsByTagName or getElementsByTagNameNS (if your elements are coded with NameSpaces).
    Then get the first entry in the resulting list and process it however you like.

  • Unable to install Adobe CS5 64 bit package created using Adobe Application Manager on Windows 7 64

    I am unable to install Adobe CS5 64 bit package created using Adobe Application Manager on Windows 7 64 bit.Basically installation rollback on Win 7 64 bit image.
    MSI Log File :-
    Property(S): ProductToBeRegistered = 1
    MSI (s) (5C:D4) [17:59:21:784]: Note: 1: 1708
    MSI (s) (5C:D4) [17:59:21:784]: Product: Adobe_CreativieSuite_5_MNT -- Installation operation failed.
    MSI (s) (5C:D4) [17:59:21:784]: Windows Installer installed the product. Product Name: Adobe_CreativieSuite_5_MNT. Product Version: 1.2.0000. Product Language: 1033. Manufacturer: Adobe Systems Incorporated. Installation success or error status: 1603.
    Please let me how to install 64 bit package on Win7 64 bit.
    Thanks in Advance.

    Ok so I downloaded the most current installer CS5.1, My previous installer was version 5.0. It did install fine fully updated to my license version. I just wanted to update in case anyone in the future has a similiar experience. Too bad this advice was not offered by the "experts" here.

  • SQL Developer 1.1.0.23.64 on Mac OSX 10.4.8 - very very bad perfomance.

    Hello!
    I just downloaded SQL Developer 1.1.0.23.64 and I'm wondered by its inappropriately bad perfomance. "Tables" and "Views" node can't be opened, and simple (very simple) query "select * from dual" executes 15 to 30 seconds. Can it be worked around in any way? Oracle versions are 10g and 9i - looks like it works the same bad way on both of them.

    I have 1.25Gb operating memory, jdk 1.5.0_06 (latest Mac JDK). I do not have neither sql*plus nor oracle client installed (and there are no such requirements in the installation guide) - everything works fine and fast enough with JDBC drivers in SQL4X as well as in projects being under development. I'm using JDBC drivers from ojdbc14.jar. The only program that very slow in SQL execution is SQL Developer, unfortunately...

  • With one package of Adobe Creative Suite 2 and the upgrade CS5 how many computers can use it?

    With one package of Adobe Creative Suite 2 and the upgrade CS5 how many computers can use it?

    You have 2 activations and no more.
    Mylenium

  • I want to upgrade to CS6 Production Premium suite from CS5.5.  Can I use CS6 upgrade made for CS5, or do I have to use upgrade that specifically states for CS5.5.

    I want to upgrade to CS6 Production Premium suite from CS5.5.  Can I use CS6 upgrade made for CS5, or do I have to use upgrade that specifically states for CS5.5.
    I am referring to the DVD installation Disks not Cloud.  Disk last release, I believe in 2012.
    Thank you.

    at the link i posted i see an upgrade for cs5 and cs5.5.
    you can contact adobe support if you don't see that.
    contact adobe support by clicking here and, when available, click 'still need help', https://helpx.adobe.com/contact.html

  • Using DOM

    Hi everyone,
    I was wondering if someone could give me a hand with the following.
    I am planning to create a simple search engine to search for products for a computer parts retailer. The list of products is stored in an XML repository , and all queries to this repository are sent as XML documents.
    The search engine web page will display a single text input field, into which a user can enter a keyword to search for
    I am using DOM to convert the Html search query to an XML document.
    Here is my DOM code so far.
    <%@page import="java.io.*"%>
    <%@page import="javax.xml.parsers.*"%>
    <%@page import="org.w3c.dom.*"%>
    <%@page import="org.apache.xml.serialize.*"%>
    <%!
    String 
    search,textfield;
    %>
    <%
    // Retrieve the Search query
    search = request.getParameter("search");
    textfield = request.getParameter("textField");
    // Create a new DOM factory, and from that a new DOM builder object
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();// Note that we are creating a new (empty) document
    Document document = builder.newDocument();
    // The root element of our document wil be <query>
    // It gets stored as the child node of the whole document (it is the root)
    rootElement = document.createElement("query");
    document.appendChild(rootElement);
    // Create an <searchterm> element , place underneath <query>
    Element searchtermElement = document.createElement("searchterm");
    searchtermElement.appendChild(document.createTextNode(searchterm));
    rootElement.appendChild(searchtermElem
    I am just wondering if my DOM code looks correct so far?

    A further cast didn't help either. For a change I have abandonded the JAXP approach and instead have built an example found at
    http://otn.oracle.com/pub/listings/vohra_xmlschema_l4.html
    that shows how to validate against a schema.
    I have changed the method to return the validated document and have then tried to apply some of the D0M validation methods supposed to return a NameList but I still always get null.
    I have posted the example Java program at
    http://home.arcor.de/martin.honnen/java/xml/Test20040308.java.txt
    and run it against the example schema and XML files at http://home.arcor.de/martin.honnen/java/xml/test20040307Xsd.xml http://home.arcor.de/martin.honnen/java/xml/test20040307.xml
    While the parsing works and the XML is judged valid according to the schema attempts to use the DOM validation methods to return a NameList fail to return one.
    Does anyone have an example using any DOM Level 3 validation interfaces/methods successfully?

  • Problem in parsing XML using DOM Parser.

    Hi,
    I am parsing an XML using DOM Parser.
    When i try to get attributes of a node, i dont get in the order it is written. For Eg. This the node:
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa">
    When i try to print the attribute values i should get in the order:
    News, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, 202, COGN-4MNMT3, aaaa
    BUT I AM GETTING IN THE ORDER:
    News, 202, /website/ing_news.nsf/ViewNewsForm?OpenForm&All, aaaa, COGN-4MNMT3
    Is there any way to sort this problem out?
    Thanks and Regards,
    Ashok

    Hi Guys,
    Thanks a lot for your replies.
    But i want to keep all the values as attributes only.
    the XML file is as shown below:
    <Menu>
    <Level0 label="News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="202" uid="COGN-4MNMT3" parentid="aaaa" children="3">
         <Level1 label="ING News" link="" level="1" uid="COGN-4MNN89" parentid="COGN-4MNMT3" children="3" >
              <Level2 label="All ING News" link="/website/ing_news.nsf/ViewNewsForm?OpenForm&All" level="2" uid="INGD-4MVTK2" parentid="COGN-4MNN89" children="0">
              </Level2>
    </Level1>
    </Level0>
    The code i was using to get attributes is:
    String strElementName = new String(node.getNodeName());
         // System.out.println("strElementName:"+node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
    int iLength = attrs.getLength();
    for (int i = 0; i < iLength; i++) {
    String strAttributes = (String) attrs.item(i).getNodeName();
    String strValues = (String) attrs.item(i).getNodeValue();
    Also is it not possible to Enforce the order using some Schema/DTD in this case?
    TIA
    Ashok

  • Problem in parsing JMS TextMessages using DOM

    Hi
    I want to parse JMS TextMessages by using DOM parser.DomBuilder's parse method supports only Strings,input stream in its constructor.
    Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
    Thanks
    Kanth

    kanth218 wrote:
    Hi
    DomBuilder's parse method supports only Strings,input stream in its constructor.This is not true. Have another look at the documentation.
    Is there anyway we can parse JMS TextMessages by using DOM.Your help would be appreciated.
    parse(new InputSource(new StringReader(someString)))

  • Parsing an XML using DOM parser in Java in Recursive fashion

    I need to parse an XML using DOM parser in Java. New tags can be added to the XML in future. Code should be written in such a way that even with new tags added there should not be any code change. I felt that parsing the XML recursively can solve this problem. Can any one please share sample Java code that parses XML recursively. Thanks in Advance.

    Actually, if you are planning to use DOM then you will be doing that task after you parse the data. But anyway, have you read any tutorials or books about how to process XML in Java? If not, my suggestion would be to start by doing that. You cannot learn that by fishing on forums. Try this one for example:
    http://www.cafeconleche.org/books/xmljava/chapters/index.html

  • Parsing xml using DOM parser in java

    hi there!!!
    i don have much idea about parsing xml.. i have an xml file which consists of details regarding indentation and spacing standards of C lang.. i need to read the file using DOM parser in java n store each of the attributes n elements in some data structure in java..
    need help as soon as possible!!!

    DOM is the easiest way to parse XML document, google for JDOM example it is very easy to implement.
    you need to know what is attribute, what is text content and what is Value in XML then easily you can parse your document with dom (watch for space[text#] in your XML document when you parse it).
    you get root node then nodelist of childs for root then go further inside, it is easy believe me.

  • Delete elements from XML file using DOM and java

    Hi
    I want now is to remove element from my XML file
    for example
    i have following xml
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
              <firstLineText />
              <firstLineText>|line11</firstLineText>
              <firstLineText>|line12</firstLineText>
    </firstLineTexts>
    </printing>how do i remove all elements fireLineText
    my final output should be
    <?xml version="1.0" encoding="UTF-8"?>
    <printing>
    <firstLineTexts>
    </firstLineTexts>
    </printing>How do i do it using DOM,
    I can create instance of DOM and write it using TransformerFactory
    Ashish

    Hi
    I am trying the following code,
    but it is not working
                    NodeList nScene = doc.getElementsByTagName("firstLineTexts");
              NodeList nScene1 = nScene.item(0).getChildNodes();
              for (int i = 0; i < nScene1.getLength(); i++)
                   Node n = nScene1.item(i);
                        nScene.item(0).removeChild(n);
              }

  • Remove element from xml using dom.

    i want to remove an element from an xml file using dom.
    i remove the element but the whole content of the file is also deleted.
    how can i rewrite the file.

    vij_ay wrote:
    subject :Remove element from xml,but if empty element in input file then output should be <tag></tag>, not like <tag.xml/>I assume you mean <tag/> but why do you want this? Any application that will not accept this valid XML construct is flawed and a bug report should be raised against it.

  • How to remove element namespaces in XML file using DOM or SAX?

    Hi Guys,
    I developed a JAVA mapping in XI to add name spaces for XML file, after mapping,name spaces xmlns="http://www.mro.com/mx/integration" and xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" were added correctly, but for some nodes, such as <Header> and <Content>, a name space xmlns="" was added automatically.Please check below files to compare.
    It looks like be added automatically by XI. I didn't process anything for these nodes in JAVA program.
    Now the issue is, how can I remove these redundant namespaces? Such as xmlns="".
    Can I remove them using DOM or SAX in JAVA Mapping?
    Thanks in advance.
    ====>Original XML file
    <?xml version="1.0" encoding="UTF-8"?>
    <LLYLPPInterface language="EN">
       <Header>
          <SenderID>GBIP</SenderID>
          <CreationDateTime>2008-02-13T22:49:34-05:00</CreationDateTime>
          <RecipientID/>
          <MessageID/>
       </Header>
       <Content>
          <LLY-LPP>
             <INVOICE>
                <INVOICELINE>
                   <PONUM>4780000008</PONUM>
                   <POLINENUM>1</POLINENUM>
                   <INVOICEQTY>1</INVOICEQTY>
                   <LOADEDCOST>68</LOADEDCOST>
                </INVOICELINE>
             </INVOICE>
          </LLY-LPP>
       </Content>
    </LLYLPPInterface>
    ===>Target XML file after JAVA mapping
    <?xml version="1.0" encoding="utf-8"?>
    <LLYLPPInterface language="EN" xmlns="http://www.mro.com/mx/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <Header xmlns="">
              <SenderID>GBIP</SenderID>
              <CreationDateTime>2008-02-13T23:11:55-05:00</CreationDateTime>
              <RecipientID/>
              <MessageID/>
         </Header>
         <Content xmlns="">
              <LLY-LPP>
                   <INVOICE>
                        <INVOICELINE>
                             <PONUM>4780000008</PONUM>
                             <POLINENUM>0</POLINENUM>
                             <INVOICEQTY>1</INVOICEQTY>
                             <LOADEDCOST>68</LOADEDCOST>
                        </INVOICELINE>
                   </INVOICE>
              </LLY-LPP>
         </Content>
    </LLYLPPInterface>
    Edited by: Eddie Zhang on Feb 14, 2008 9:22 AM
    Edited by: Eddie Zhang on Feb 14, 2008 9:24 AM

    Hi Milan,
    Thanks for your replay.
    Actually when I used module XMLAnonymizerBean to convert namespaces, the header of XML, such as <?xml version="1.0" encoding="UTF-8"?> was converted to format <?xml version='1.0' encoding='UTF-8'?>, quote was converted to single quote. Although I set parameter anonymizer.quote = ", it still didn't work, single quote appeared instead of quote.
    I'm not sure why this happened. Can anyone help to clarify this?
    Thanks
    Edited by: Eddie Zhang on Feb 15, 2008 2:11 AM

Maybe you are looking for

  • How do I save a PNG file with an alpha channel in Photoshop CS5?

    I have a PNG file created in Photoshop and I need to save it with an alpha channel for web purposes. I tried 'Save for Web & Devices' and selecting the Transparent box. Then, after saving, when I select 'get info' for the file it says there is no alp

  • OLE2 and DDE package books

    Hi All, I need to fully understand OLE2 and DDE package. Pressing F1 provides very limited help for me. Anyone here have or know some links of any reading materials(e-books, documentation)? Please share... I'm drowned with my tasks here. Thanks!

  • How do I center my background image and get a round border radius?

    <!--I thought I had pretty straight forward CSS, but the image is way to the top and I can't create a border radius. Below is my CSS--> body {   background-color: rgba(30,30,30,1);   background-image: url('images/me_atsunsetbackground1.JPG');   backg

  • Help - Photos to iMovie

    Can I drag photos directly into iMovie or do need to import them into iPhoto first? The files are nef/RAW

  • RAW+JPEG Import Question

    I switched from Windows/LR to Mac/Aperture last year and have a question about importing RAW and JPEG files. My camera (Olympus EM5) finally has RAW support and I have been shooting RAW+JPEG. I got a preset that I like to apply to the RAW files durin