Loop through all of the xml elements

How do I loop over all xml tagged in a story? I created a reference to the xml elements of the story I want to like this:

var xmlStory = myDoc.xmlElements[0].xmlElements[0];

In this structure, I have items < v > 10 / < v >, which I want to change of < id v '10' = > 10 / < v >. I want to do in the InDesign scripting and not with XSL export because of workflow, I plan. I know I can loop on children in the structure like this:

for(var i=0;i<xmlStory.xmlElements.length;i++){
                    if(xmlStory.xmlElements[i].markupTag.name == "v"){
                              xmlStory.xmlElements[i].xmlAttributes.add("id", xmlStory.xmlElements[i].contents);
                   }
         }

This works very well for the first level, but I want to find all elements with the tag '< v >. These tags can appear at any level in the structure. How can I make sure that all of them are included and not just the first elements of the child of the element of the story?

Try this,

#target inDesign;

var doc = app.activeDocument;
xmlTag var = doc.xmlElements [0];
var vTag = xmlTag.evaluateXPathExpression("//v")
for (var i = 0; i)<>
{
Try
{
vTag [i].xmlAttributes.add ("id", vTag [i].xmlContent.contents)
}
{catch (e)}
}

Tags: InDesign

Similar Questions

  • I need to find all of the XML elements and add a line break for the text of each of them

    I need to find all XML elements and to add a line break the text of each of them.

    Is it possible with a script?

    Try this piece of code as it is. I hope that's what you want...

    var myDoc = app.activeDocument;
    var inddRooElement = myDoc.xmlElements.item(0);
    var xPathElements = inddRooElement.evaluateXPathExpression("//*");
    var elementCount = xPathElements.length;
    for(var eId=0; eId
    

    ----------------

    Green4ever

  • Loop through all the items in a collection

    I need to loop through all the elements of a collection in a VB.NET program that uses the InDesign API. For example, I want to loop through all the pasta spread masters in a document. Here is my sample code:

    Dim I As Integer = 0

    Var MyApp as InDesign.Application = Nothing

    Var MyDoc as InDesign.Document = Nothing

    Var MyPage as InDesign.Page = Nothing

    MyApp = CType (Activator.CreateInstance (Type.GetTypeFromProgID ("InDesign.Application"), True), InDesign.Application)

    MyDoc = CType (MyApp.Documents.Add (False), InDesign.Document)

    With MyDoc

    With. DocumentPreferences

    . PageHeight = "8.5I".

    . PageWidth = "5.5i."

    Ends with

    With. ViewPreferences

    . HorizontalMeasurementUnits = InDesign.idMeasurementUnits.idPoints

    . VerticalMeasurementUnits = InDesign.idMeasurementUnits.idPoints

    Ends with

    If. MasterSpreads.Count > 0 Then

    For I = 0 To. MasterSpreads.Count - 1

    Dim ThisMasterSpread As InDesign.MasterSpread = CType (.) MasterSpreads.Item (I), InDesign.MasterSpread)

    Next I

    End If

    Ends with

    When it runs, I get an error on the last Dim statement which defines ThisMasterSpread. It highlights. MasterSpreads.Item (I) and gives the following error:

    COMException was unhandled: the Member required to the collection does not exist.

    How I managed to loop over all the pasta spread masters?

    Thank you!

    A lot of trial and error, I discovered the answer to my own question: the Collections are 1-based, not 0-based. My statement

    For I = 0 To. MasterSpreads.Count - 1

    should be

    For I = 1 To. MasterSpreads.Count

  • To loop through all the variables on an image

    Hello. I am trying to write a method to save the State of the game that I do. I am able to loop through all the clips and get their existing frameworks, but is it possible to loop through all the variables on the current frame (without knowing their names) and put them in a table?

    Thanks 4 any help

    trigger2160

    Thanks for the help. A container object is just what I wanted, even though I knew not u can do. my variables are not accessible directly so I managed to change the way they were stored easily without negative effects for the rest of the game. Now I can also save and load the State of the game which entered 4 will facilitate 4 me to test.

    trigger2160

  • How to separate the content of the XML element

    Hi all

    How can we separate content of the XML element in two strings, where each string will be copied to new variables.

    For ex:
    The entry that I get is

    C:/documents/sharedFiles/Apple.PDF < XmLElement > < / XMLElement >

    now I want to break the content into two parts as

    < yyyy > C:/documents/sharedFiles / < / aaaaa >
    Apple.PDF < bath > < / bath > (I want to separate the file name string)

    and now I want to copy it in two other variables. How can I achieve this in BPEL. Appreciate your help.

    Thank you

    Published by: kameshb on March 25, 2013 11:16

    Hi Philippe,.

    I tried this on a simple XSL and achieve the desired results:

    Entry:
    ------------

    C:/test/dummy/post/test.PDF










    It will be useful.

    Thank you
    Deepak.

  • Create the XML element for the cell in the chart CC2015

    Hello world

    I am currently working with the xml element.

    And I want to create xml, table cell element.

    For now, I can create xml for the graphic cell by select graphic image of that cell, and then call the AutoTag() function.

    But I want to create an xml element of a chart without selected cell.

    I found the function () Utils < IXMLElementCommands >-> CreateElement()

    but it doesn't seem to work with a graphic table cell structure.

    Does anyone know how to do?

    Thanks in advance.

    Try,

    InterfacePtr cellContent (tableModel-> QueryCellContentBoss (gridAddress));

    if(cellContent == Nil) {}

    break;

    }

    InterfacePtr cellXMLReferenceData (cellContent, UseDefaultIID());

    {if(!cellXMLReferenceData)}

    break;

    }

    XMLReference cellXMLRef is cellXMLReferenceData-> GetReference();.

  • How to add content in the xml element?

    I need to insert a word sqrt (plain text without tags) in the xml element of m:msqrt as below:

    enter image description here

    I tried,

         

    var path = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString () replace (/ \ / g, ' /'); document path (sample.indd) active

    var xmlPath = (app.activeDocument.fullName.parent.fsName) m:System.NET.SocketAddress.ToString (.replace(/\\/g, '/')) + "" / with_aid2.xml ";"

    xmlFile = file (xmlPath);

    {if (xmlFile.Exists)}

    xmlFile.open ();

    var myString = xmlFile.read ();

    xmlFile.close ();

    myXml = new XML ();

    myXml = XML (myString);

    var msqrtCount = myXml.xpath("//m:msqrt");

    } else {alert (xmlPath + "does not exist!") ;}}

    for (var i = 0; i < msqrtCount.length (); i ++) {}

    var added = msqrtCount [i];

    added.contents = "sqrt";

    }

    I get an error indicates the invalid content property.

    Try this,

    var myDoc = app.activeDocument;
    mySqrtTag(myDoc)
    function mySqrtTag(elm)
    {
        for (var i = 0; i < elm.xmlElements.length; i++)
        {
            if(elm.xmlElements[i].markupTag.name.toString() == "m:msqrt")
            {
                elm.xmlElements[i].insertionPoints[0].contents = "sqrt";
            }
            mySqrtTag(elm.xmlElements[i]);
        }
    }
    
  • Apply the style of Pará to the xml element based on the type of master page?

    IM using a flow xml, im importing the xml to be used across different master page templates and I want to apply paragraph styles different items depending on what master page xml, they are on...

    So I have 3 put templates in place

    Type of page 1

    Type of page 2

    Type of page 3

    and 3 paragraph styles

    style 1

    style 2

    style 3

    I have the same xml structure deposited on each page...

    < Entry >

    < name > Page < / name >

    < / name >

    So, can I use javascript to apply the paragraph (style 1) style to the xml element (name) on any page that uses the master page (type of Page 1)

    Is this possible? whether and how this could be done?

    Thanks in advance

    Hello

    Try:

    #include '... / XML rules/glue code.jsx ";

    myDoc var = app.documents.item (0);

    var myRuleSet = new Array (new applyParaStyle());

    {with (MyDoc)}

    var elements = xmlElements;

    __processRuleSet (Elements.Item (0), myRuleSet);

    }

    function applyParaStyle() {}

    myIdName = "Xp".

    This.XPath = "//restaurant_name";

    This.Apply = function (myElement, myRuleProcessor) {}

    {with (MyElement)}

    {Switch(insertionPoints[0].parentTextFrames[0].) ParentPage.appliedMaster.Name)}

    case "X-Master:

    App.Select (texts);

    App.Selection [0]. FillColor = myDoc.colors.item ("xxxx");

    break;

    case 'guide-Scotland:

    App.Select (texts);

    App.Selection [0]. FillColor = myDoc.colors.item ("scotland");

    by default:

    break;

    }

    }

    Returns true;

    }

    }

  • I need the XML elements appear in the various paragraphs...  Could do with a script?

    I need of the XML elements appear in different paragraphs ...
    Pourrait to do this with a script?

    Thank you...

    You can use this / Puedes usar esto

    insertTextAsContent("\n",XMLElementPosition.beforeElement);
    //  or
    insertTextAsContent("\r", XMLElementPosition.afterElement);
    

    Necesitaria mas information,

  • Add the ID of the XML element to all elements as an attribute

    Hello

    The title says I hope that what I like to do. I have quite some documents that are marked, but add an id to all the elements of better handling external XML in Indesign. I've been looking around a bit but seems not forever be disturbed by many people...

    So, how can I iterate through all my items in XML and adds the ID of the element as an attribute?

    Thank you

    Koen

    Hi Koen,

    Please try the JS code below. This code its InDesign CS5.5 work.

    var myDoc = app.activeDocument;
    try{
        var rootElement = myDoc.xmlElements.item(0);
        var linkElementList = rootElement.evaluateXPathExpression("//para");
        for(i=linkElementList.length-1; i>=0; i--){
            var myAttribute = linkElementList[i];
            myAttribute.xmlAttributes.add("idname", "idvalue");
            }
        }catch(e){}
    

    THX,

    csm_phil

  • Work Dbma_scheduler execution of procedure which loops through all the customer drawings in the rear rollers database transaction in case of exception

    Hello

    Need your contributions on the approach to implement a work using dbms_scheduler.

    We have about 2000 drawings. Each schema has a package with 2 procedures.

    The requirement is to create a single job in SYS that loop over each schema and run the procedures specific to a time (once a day) and send a notification by e-mail on success or failure.

    Working script:

    BEGIN

    dbms_scheduler.create_job (job_name = > 'LOAD_EACH_SCHEMA_AUDIT_DATA',)

    job_type = > 'PLSQL_BLOCK ',.

    job_action = > ' BEGIN sys.p_loadaudit;

    END;',

    start_date = > systimestamp,

    repeat_interval = > ' FREQ = MINUTELY; RANGE = 1',

    number_of_arguments = > 0,

    enabled = > true,

    Comments = > "Use repeat interval is every five minutes");

    END;

    /

    Note: to test the end I put him repeat interval to carefully.

    Use of procedure must be running:

    Procedure sys.p_loadaudit:

    CREATE OR REPLACE

    PROCEDURE p_loadaudit

    AS

    v_count NUMBER: = 0;

    lv_error_message VARCHAR2 (4000);

    vstmt VARCHAR2 (4000);

    BEGIN

    I'm IN

    (SELECT username FROM dba_users WHERE username LIKE '% ABCFIRM')

    )

    LOOP

    vstmt: = "begin" | i.UserName | '. pkg_audit_info.p_load_coa; end;';

    EXECUTE immediate vstmt;

    vstmt: = "begin" | i.UserName | '. pkg_audit_info.p_load_am; end;';

    EXECUTE immediate vstmt;

    END LOOP;

    EXCEPTION

    WHILE OTHERS THEN

    lv_error_message: = ' error in procedure p_loadaudit: ' | SQLCODE. "- ERROR -" | SUBSTR)

    SQLERRM, 1, 300). '*' || dbms_utility.format_error_backtrace;

    raise_application_error(-20002,lv_error_message);

    END p_loadaudit;

    /

    Example of a scheme: SCHEMA_01

    create or replace

    PACKAGE pkg_audit_info

    AS

    CursorType type

    IS

    REF

    CURSOR;

    PROCEDURE p_load_COA;

    PROCEDURE p_load_AM;

    END pkg_audit_info;

    /

    create or replace

    Pkg_audit_info body PACKAGE

    AS

    PROCEDURE p_load_COA

    AS

    BEGIN

    INSERT INTO TABLE1();

    EXCEPTION

    WHILE OTHERS THEN

    lv_error_message: = ' error in procedure pkg_audit_info.p_load_COA: ' | SQLCODE

    || "- ERROR -" | SUBSTR (SQLERRM, 1, 300). '*' || dbms_utility.format_error_backtrace;

    RAISE_application_error(-20002,lv_error_message);

    END p_load_COA;

    PROCEDURE p_load_AM

    AS

    BEGIN

    INSERT INTO TABLE2();

    EXCEPTION

    WHILE OTHERS THEN

    lv_error_message: = ' error in procedure pkg_audit_info.p_load_AM: ' | SQLCODE.

    "- ERROR -" | SUBSTR (SQLERRM, 1, 300). '*' || dbms_utility.format_error_backtrace;

    RAISE_application_error(-20002,lv_error_message);

    END p_load_AM;

    END pkg_audit_info;

    /

    Table1 and table1 exist in schema_01.

    All 2000 patterns have same package.procedures.

    For security reasons, I removed the actual code.

    I was able to complete the task successfully. However, when a scheme procedure (SCHEMA_01.pkg_audit_info.p_load_COA) throws an exception, the job fails, and any transaction is rolled back.

    Is it possible to loop through each schema and run the corresponding procedures. Even if the exception occurs, it must restore only for this scheme and continue other patterns in the loop?

    Please let me know if there is a better way to do this. Is the way I'm handling exceptions in the work or the correct procedure?

    Thank you

    Hello

    RAISE_APPLICATION_ERROR will cause the program to exit to the appellant, even if you put it inside a block in the loop, so the statement RAISE or RAISE_APPLICATION_ERROR must be placed in your procedures 'pkg_audit_info.p_load_AM' and 'pkg_audit_info.p_load_coa '. In this way, you can use a block inside the loop and the error in the log.

    I'm IN

    (SELECT username FROM dba_users WHERE username LIKE '% ABCFIRM')

    )

    LOOP

    BEGIN

    vstmt: = "begin" | i.UserName | '. pkg_audit_info.p_load_coa; end;';

    EXECUTE immediate vstmt;

    vstmt: = "begin" | i.UserName | '. pkg_audit_info.p_load_am; end;';

    EXECUTE immediate vstmt;

    EXCEPTION

    WHILE OTHERS THEN

    --> Set the error in a table of otherwise custom event log you won't know what happened for this scheme: don't forget the user name

    END;

    END LOOP;

  • How to navigate through all of the links in the links Panel in the user interface?

    Hello world

    I wonder how I can browse all the links in the links Panel, programmatically. I have a document where the resources present in this Panel are not available using the ILinkManager. He tells me there are no links in the document when using ILinkManager-> GetLinkCount().

    These resources are not more related to any element on the page. These are images which are not more related to what it is. Right-click on it and click on 'join the link' shows nothing in the document (the same operation on a resource that is linked to a graphic image focuses on it). I can manually re-edit the link, but nothing more.

    In the user interface, there is no way to delete (not menu 'remove' or whatever).

    I think I "created" them as follows: during the creation of the story, the story is tagged. Then I attach a picture frame and label it in the history. Then I remove the frame (s) containing the history, so that its history xml is "not placed" (see kXMLUnplaceCmdBoss). At this time (if I'm not mistaken), I created these inaccessible resources. I see the xml story unplaced in the structure of the document that remains not placed XML (in the backup store) and resources in the links Panel.

    History unplaced XML CAN be removed manually, but not these inaccessible resources. However, there must be a way, as InDesign can display them.

    How to reach these 'lost' resources and delete them, by programming?

    Independent of your real problem, I would first try the equivalent in the user interface.

    Preparation:

    To simplify things and make them visible, working on a traditional tale - not the backup store.

    The story should be labeled and will remain so.

    Add content as complicated as you want.

    Some content preceding and behind it must survive.

    Your content must be labeled - surrounded by a single label.

    Text-Select this unique tag (see the invisible etc for the right selection).

    Remove the text selection.

    See: Tags are gone, content text disappeared, the images have disappeared.

    Now find a way to perform this deletion text programmatically. Without specific code XML - operation but a simple text, InDesign will do the rest.

    Finally, use the code that results on the backup store.

  • How can I save the references to the elements of the xml elements page?

    Hello

    I am trying to add coordinates of the page elements to their associated as xml attributes xml elements.

    I can easily create xml help items

    myDocument.mapStylesToXMLTags ();

    Now, I want to browse the xml document and find details of each element of the associated page and then add them in the corresponding as attributes xml node.

    In other words, I'm trying a code (assuming that all the nodes as children of the root for simplicity) as follows:

    for (var i = 0; i < myRootXMLElement.xmlElements.length; i ++) {}

    var myElement = myRootXMLElement.xmlElements.item (i);

    var myElementsPageItem = * did not find a reference of function / correct documents *.

    var myBounds = myElementsPageItem.visibleBounds;

    addORupdate (myElement, "y1", myBounds [0]);

    addORupdate (myElement, ' x 1', myBounds [1] ");

    addORupdate (myElement, "y2", myBounds [2]);

    addORupdate (myElement, ' x 2', myBounds [3] ");

    }

    In my example of document all the xml that is created by mapStylesToXMLTags() are history of type.

    So I need a way to refer to the corresponding (or rectangle) page element of the history so that I can add information about contact information item xml as attributes.

    Thank you very much...

    myElement.xmlContent.parentTextFrames was not defined in the xml document that is generated by mapStylesToXMLTags()

    After some research the object model, I found my data in

    myElement.xmlContent.textContainers [0]

    Thank you

    Halin

  • How the XML element used in RTF PUBLIC/PRIVATE? I know how to hide columns in RTF, but do not know how to generate xml below way. Help, please.

    Hello

    I'm following link below to show/hide my columns dynamically. See "formatting of column.

    http://docs.Oracle.com/CD/E12844_01/doc/BIP.1013/e12187.PDF

    According to the doc element can be made in private/public.

    <items type="PUBLIC">
     <item>
      <name>Plasma TV</name>
      <quantity>10</quantity>
      <price>4000</price>
     </item>
     <item>
    

    And even can be used to hide the column with the help of State

    <?if@column:/items/@type="PUBLIC"?>
    

    MY QUESTION IS HOW TO DO THIS IN MY XML BELOW?

    Here's the part of my XML code that I use in the definition of the data to RTF.

    <group name="GH3" source="QH3">
    <element name="COLUMN_HEAD3" value="COLUMN_NAME" /> 
    </group>
    <group name="GH4" source="QH4">
    <element name="COLUMN_HEAD4" value="COLUMN_NAME" /> 
    </group>
    

    I'm out like that.

    <LIST_GH3>
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4>
    <GH4>
    <COLUMN_HEAD4>XYZ</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    

    In order to use the logic according to the oracle document I want output like this.

    <LIST_GH3 type="PUBLIC">
    <GH3>
    <COLUMN_HEAD3>REBILL_TO_OTHER_BUSINESS_UNIT</COLUMN_HEAD3>
    </GH3>
    </LIST_GH3>
    <LIST_GH4 type="PRIVATE">
    <GH4>
    <COLUMN_HEAD4>BLANK</COLUMN_HEAD4>
    </GH4>
    </LIST_GH4>
    

    Should what changes I make in my XML to get the result of the execution as above? Help, please. Where should I make changes in the XML above? Name of the Group? Name of the element?

    I intend to use it under condition in RTF model to hide the column, but do not know how to set the column as PRIVATE/PUBLIC type in the XML output that is used to populate the data in the RTF while running.

    <?if@column:/BTSPIEXP/LIST_GH3/@type=”PUBLIC”?>COLUMN_HEAD3<?end if?>
    

    Kind regards

    Patricia K.

    Hello

    Problem has been resolved. I used the value of the item to determine whether to show it.

    Kind regards

    Patricia K.

  • The location of the XML element - predicate

    Hello

    I'm trying to bind a text field to the Designer 8.1 to a specific XML element.

    An example of XML structure:

    < KeyValueGroup >

    < ID >

    Name1 < name > < / name >

    Value1 < value > < / value >

    < /ID >]

    < ID >

    name2 < name > < / name >

    value2 < value > < / value >

    < /ID >

    < ID >

    < name > Name3 < / name >

    Value3 < value > < / value >

    < /ID >

    < / KeyValueGroup >

    I tried to link using $record. KeyValueGroup.ID [Name = "Name2"]. Value to return the value of the property name2, but the designer rejects this expression.

    Anyone would be able to advise where I'm wrong?

    I understand that I could achieve this by using a Javascript function that lists the table ID, but would prefer a solution not involving not JavaScript if possible.

    Any help appreciated,

    Matt

    Hi Matt,

    The $record refers to the current subtree of the DOM data, so in your case $data. KeyValueGroup and $record are the same thing.

    You also need a "." before the predicate.

    In any case, try $record.ID. [name == "Name2"]. Value

    Good luck

    Bruce

Maybe you are looking for