[CS3] [JS] add XML  Element to Insertion Points

hi list,
i'll do some text parsing in indesign cs3 intended to add some xml elements to my document.
i just wonder why i can't markup an insertion point. is the following approach correct? The code works fine, only the return value (stored in the _xml variable) is not the new element but the parent element. The same code works without using the insertion point (marking up the text object [xmlElements.add(_dokument.xmlTags.item("index") , erg[0]))] ).
Any ideas or thoughts?
var _dokument = app.activeDocument;
main ();
// ** main ()
function main() {
//Set the find options.
app.findGrepPreferences = NothingEnum.nothing;
app.changeGrepPreferences= NothingEnum.nothing;
//find any string encloased by @
app.findGrepPreferences.findWhat = "@.*?@";
erg = _dokument.findGrep();
while (erg.length > 0) {
_xml = _dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item( "index") , erg[0].insertionPoints[0]);
erg[0].contents = "";
erg = _dokument.findGrep();

hi dave,
gui testing is always a good idea :-) but in this case the behaviour is different:
your observation is correct (anyway at least a strange behaviour compared to any xml editing tool i know == how adobe intended to insert an empty element?), tagging in the gui a tagged insertion point tags the whole story.
in the script a new element is added but the return value is the parent element (the xmlElement of the whole story).
this causes a problem when i add an attribute (the intention of the above script is to add references) which is added to the parent element.
gregor

Similar Messages

  • Add XML Element ID to all elements as attribute

    Hi There,
    The title hopefully states what I like to get. I'm having quite some documents that are tagged, but want to add an id to all elements to allow for better XML manipulation outside on Indesign. I've been looking around a bit but seems to be not to many people ever bothered with...
    So, how do I traverse through all my XML elements, and add the element ID as attribute ?
    Thanks,
    Koen

    Hi Koen,
    Please try the below JS code. This code its working fine in InDesign CS5.5.
    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

  • Add xml element error

    I am trying to add a new element to an xml file, I has 5
    existing, so I am trying to add the sixth. but got an error
    message, anyone could help me on this?
    Thanks,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The index of a child element is out of range.
    There are only "5" children under this node.
    Therefore index "6" is out of the allowed range [1-5].
    The error occurred in
    C:\CFusionMX7\wwwroot\myfolder\addNew.cfm: line 18
    16 : newNodePos =
    arrayLen(variables.xml.machii.listeners.listener) + 1;
    17 : // add new node then set it's attributes
    18 :
    variables.xml.machii.listeners.listener[variables.newNodePos]=
    XMLElemNew(variables.xml,"listener");
    19 :
    structInsert(variables.xml.machii.listeners.listener[variables.newNodePos].XmlAttributes, "name","#form.listenerName#",1);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    here the code:
    <cfscript>
    // get array position of next XML child to add
    newNodePos =
    arrayLen(variables.xml.machii.listeners.listener) + 1;
    // add new node then set it's attributes
    variables.xml.machii.listeners.listener[variables.newNodePos]=
    XMLElemNew(variables.xml,"listener");
    structInsert(variables.xml.machii.listeners.listener[variables.newNodePos].XmlAttributes, "name","#form.listenerName#",1);
    </cfscript>

    Did it help? I am using the new jwsdp 1.2 and have a jaxrpc-ri.xml
    like this;
    <webServices>
        <endpoint name="EP1"/>
        <endpoint name="EP2"/>
        <endpointMapping
            endpointName="SyndicationServerEP2"
            urlPattern="/ep1/*"/>
        <endpointMapping
            endpointName="EP2"
            urlPattern="/ep2/*"/>
    </webServices>But after running wsdeploy, in the resulting web.xml only EP2
    is mentioned!
    Any hints?
    Hans

  • [JS] [CS3] How do you find an insertion point's paragraph index #?

    This is probably a very simple thing to do, but I haven't been able to find a way to reference this. Thanks in advance for any help provided.
    Len Swierski

    The unexpected higher number is exactly the problem. The paragraph index property has nothing to with the paragraph array position; it's the index of the first character of that paragraph. (Sorry -- you'll have to re-read that post ...)
    Fortunately you can still use the returned number. Using the handy function everyItem() on the text frame's Paragraphs collection, you can gather all "first character" indexes into an array. Then it's only a case of testing your InsertionPoint index against the values.
    Suppose you copy this post into InDesign and inspect each of the paragraph's indexes. You would get an array like this:
    [0, 237, 238, 508, 509 ]
    The first value points to the start of the first paragraph in "character count mode". The second value points to the empty line below the first paragraph (I suspect it points to the Return character in InDesign). Since there is nothing else on that line, the next paragraph starts exactly one character after that.
    I think the following script does what you need -- but beware! It works, just as you asked, on individual text frames. It even works correctly if the text frame starts in the middle of a paragraph in the previous linked textframe, and this paragraph will correctly be reported to be "#0" of the current frame.
    ip = app.selection[0].insertionPoints[0];
    parIndex = getParIndex(ip);
    alert (parIndex);
    function getParIndex (someIp)
         var allPars = someIp.parentTextFrames[0].paragraphs.everyItem().index;
         var loopy;
         for (loopy=allPars.length-1; loopy > 0; loopy--)
              if (someIp.index >= allPars[loopy])
                   return loopy;
         return 0;

  • Preserve whitespace in XML element value

    I am trying to add XML element with value prefix with white space:
      ex_doc->create_simple_element(
          name = 'VALUEPART1'
          value = '          BQ/XWKB-99-5-9999-2'
          parent = lo_ele_e1bpparex_bape_vbak ).
    But when the XML is create, the white space is removed! How can I preserve the white space???
    <VALUEPART1>BQ/XWKB-99-5-9999-2</VALUEPART1>
    What i want is:
    <VALUEPART1>          BQ/XWKB-99-5-9999-2</VALUEPART1>
    Appreciate for any help

    Hi,
    if you had been using XSLT instead, I would have said 'remove the strip-space element or alter it according to your needs'...
    Please provide what class you are using, else it's too generic..
    regards, Lukas

  • Selecting the content of XML element CS3(JS)

    Hi
    I am trying to select the whole content of XML Element.
    I am trying like this
    app.activeDocument.xmlElements[i].select();
    But it is not working.
    Regards
    Suresh

    A few hints:
    Perhaps your variable
    i i
    is not defined. If that's the case, give up trying to write code for this complicated job! XML is not the easiest part of ID to begin with. Starting with uninitialized variables and flagging that as an error (and complaining about that in a forum) is a beginners' blunder.
    If I run your script line with i set to 0, the first element of my XML structure is selected. I can see with my own eyes it works, because I have the XML Structure pane in ID open. If I click on the 2nd element there and run your script line, the top (= 0th) element is selected. Perhaps you didn't open the XML Structure view so you did not see it worked after all. Or perhaps you expected something
    i else
    to be selected -- the text content, maybe -- so you tag it as "error". That's a misinterpretation of what the XmlElement object is. Understandable, but still not an error. You can have lots of XmlElements without any text or other object associated. If it was your intention to select whatever the xml element contains, try working with the property 'xmlContent'. From its description I gather that sort-of does this alternative interpretation, i.e., you can select the
    i text
    which is pointed to by the element. Untried. But do read on.
    If I run your script with i = 1, I
    i do
    get an error, and it's perfectly valid too! "Object is invalid" -- well, of course it is. There is no other XML element at that level. An app.document.xmlelements entry always points to the
    i root
    of the XML, and you can only have one. Perhaps you expected #1 to be the next sub-element. Well, not so in the ID implementation -- as usual for almost all XML based structures, it's a tree. The "next" element is xmlElements[0].xmlElements[0], which you can check by changing your line to
    >app.activeDocument.xmlElements[0].xmlElements[0].select();
    and verifying the 2nd element from the top is selected in the XML Structure view.

  • [JS][CS3] Insertion Point

    HI All
    I need to get a hold of an insertion point between 2 characters and add some negative kerning to the characters either side.
    I have tried:
    myInsertion = myPara.characters[-3].insertionPoints;
    and many variations of that line, but with no joy.
    Can someone please help me out here?
    Cheers (as always)
    Roy

    This will set the kerning on each side of that character to a specific value:
    myPara.characters[-3].insertionPoints.everyItem().kerningValue = -25;
    If you want to use different values, then:
    myPara.characters[-3].insertionPoints[0].kerningValue = leftKern;
    myPara.characters[-3].insertionPoints[1].kerningValue = rightKern;
    where leftKern and rightKern hold the values you want.
    Dave

  • Find text from current insertion point - indesign cs3 javascript

    Hi all,
    I need to find the text from the insertion point in CS3 document through javascipt. Built in indesign has this feature. I want to do this in my script.
    Anybody have the idea/solutions for ths...
    Thanks,
    Vaasu

    Thanks csm_phil for your interest... see my below code:
    if(app.documents.length>0)
        myDoc=app.activeDocument;
        var myFoundchar=new Array();
        app.findTextPreferences = NothingEnum.nothing;
        app.changeTextPreferences = NothingEnum.nothing;
        app.findGrepPreferences=     NothingEnum.nothing;
        app.findGrepPreferences.fontStyle="Italic"
        app.findGrepPreferences.findWhat ="[\\l\\u].+?( v\. ).+" //"(.+?(v\.).+)";
    var myResults = myDoc.findGrep();
    for (var i = 0; i < myResults.length; i++)
            alert(myResults[i].contents);
        app.findGrepPreferences=     NothingEnum.nothing;
        app.findGrepPreferences.findWhat =", \\d{1,}.+?\\d{4}?\\) ";
        var mySearch = myDoc.findGrep();
        app.select(mySearch[0].insertionPoints[0]);
        alert(mySearch[0].contents);
        app.findGrepPreferences = null;
    alert("Done");
    here i am trying the fetch the Table of cases, example find results are
    Sears, Roebuck & Co. v. Camp, 124 N.J. Eq. 403, 407 (E. & A. 1938)
    Sears, Roebuck & Co. v. Camp, 124 N.J. Eq. 403, 408 (E. & A. 1938)
    Gramatan Nat’l Bank & Trust Co. v. Backman, 30 N.J. Super. 349 (App. Div. 1954)
    So, the 2nd search mysearch always giving first line output above.           , 124 N.J. Eq. 403, 407 (E. & A. 1938)
    If i use the  mySearch[i].contents sometimes it doesn't give the correct result. Since, if gives if other than the case name ends with , and digits. It makes the result totally wrong.
    Thanks,
    vaasu

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

    I need to find all XML elements and add a line break to the text of each of them.
    Is this possible with a script?

    I need to go from this ...
    to this...
    but looking for the XML elements (not paragraphs) and then adding text ...
    Thanks for your attention !!!

  • Remove xml element using JS[CS3]

    Hi, I have an xml structure where i want to remove some paritcular element named "extlink".
    I do have one script with me but it doesn't wipe out all specific xml element from structure.
    var myDoc = app.activeDocument;
    var foundtext = 0
    Query_Remove (myDoc);
    alert ("You have removed " + foundtext + " " +" Link !!")
    exit (0);
    function Query_Remove(elm)
    try
    for(var i=elm.xmlElements.length-1; i>=0; i--)
         if((elm.xmlElements[i].markupTag.name == "extlink") && (elm.xmlElements[i].xmlElements[0].markupTag.name == "http"))
        var Store_CitAttri = elm.xmlElements[i].xmlElements[0].xmlAttributes.item("c_style").value;
         if(Store_CitAttri == "URL")
          elm.xmlElements[i].remove();
         foundtext = foundtext + 1;
       Query_Remove(elm.xmlElements[i]);
    catch (e){
    Some time it skip the element from all figure captions and some time from body text and some time it works perfectly
    Could any one figure it out why this script behaviour is not consistent as i am new to scripting and not getting any idea about this.
    Thanks
    Mac

    Okay, after peering over your code and trying a few things out I see one immediate problem and one possible improvement.
    The problem lies in this:
    1. if condition is true, remove item
    2. check recursively
    The problem is .. if an item is removed, the following recursive check will always fail. However, the entire loop is wrapped into a try..catch, so InDesign will not alert you that it failed. Instead, it will continue with what's after the loop, exactly because the try..catch is around the entire loop!
    Change the loop code to this
    if((elm.xmlElements[i].markupTag.name == "http") && (elm.xmlElements[i].parent.markupTag.name == "extlink"))
        var Store_CitAttri = elm.xmlElements[i].xmlAttributes.item("c_style").value;
        if(Store_CitAttri == "URL")
          elm.xmlElements[i].remove();
           foundtext = foundtext + 1;
           continue;
    Query_Remove(elm.xmlElements[i]);
    so the recursive checking is skipped. You can also remove the entire try..catch block, as this may hide additional errors ...
    The improvement is: as I started reading this thread from the top again, shouldn't you be removing the "extlink" items, rather than just the "http" ones inside?
    If so, remove the parent of the found item (which is always the "extlink"):
          elm.xmlElements[i].parent.remove();
    -- and, as this will break the loop (because you just removed the set of elements it was working in!), replace 'continue' with 'return'.
    Hope this helps

  • [CS3 JS WIN] Get XML Element of paragraph?

    Im trying to get the xml element of a selected paragraph.<br />ie:<br /><br /><item><br /><text><br /><code> This is some code </code>   <--this is selected in indesign<br /></text><br /></item><br /><br />When I try to use associatedXMLElements[0].xmlElements - it returns all different elements(item,text,code,etc) how do I get it to return the immediate XML Element?

    Well what I'm doing is selecting a textframe and then looping through the paragraphs, passing them to the procXML function which is when I try to get the xml element.
    The forums ate my structure:
    [item]
    [text]
    [code]This is some code[/code]
    [/text]
    [/item]

  • How to insert Text physically to xml in xml Element

    hello friends,
    I am newb of jDom. i am trying to change xml "Element's"--->"Text". My xml is as follows .....
    <?xml version ="1.0">
    <Elements>
             <code>
                       <data>EE550</data>
             </code>
    </Elements> I am trying to replace that "<data>" by <data>AA550</data>
    my code is as below
                 SAXBuilder sb = new SAXBuilder();
                 Document doc = sb.build(new File("src/xml/M90EE.xml"));
                 Element element = doc.getRootElement();
                 List children = element.getChildren();
                 String key = (element.getChild("text").getChild("mkey").setText("AA550").getTextTrim());   System.out.println("mkey       :"+key);
    output:
    mkey   :AA550 but is it possible to change in the xml file phisically.
    thanQ
    Ajay

    hello Reegz,
    ThanQ so much for perfect solution....
    when i do like that it is actually adding text to the existing Element Text.. so i wrote as follows....
    SAXBuilder sb = new SAXBuilder();
    Document doc = sb.build(new File("src/xml/M90EE.xml"));
    *String skey = (element.getChild("text").getChild("mkey").removeContent().toString());*     //--------->step 1
    *String skey1 = (element.getChild("text").getChild("mkey").addContent("ISO9001").toString());* //-------->step 2     
    String rdmkey = (element.getChild("text").getChild("mkey").getTextTrim());
    XMLOutputter serializer = new XMLOutputter();
    String str = serializer.outputString(doc);
    FileWriter fr = new FileWriter("src/xml/M90EE.xml");
    fr.write(str);
    fr.flush();
    fr.close();Is there any other way to replace text in step1 and step2 other than above or will it be enough for multiuser programming. Because this application will be accessed by so many number of user's what do u sujjest.
    thanQ ...
    Han.

  • [JS] CS3 Apply document defaults to insertion point

    Is there any way to apply the document defaults to an insertion point? I
    have a script that is looping through a whole bunch of text files,
    formatting them (with thinks like tab stops and indents). The thing is I
    don't want any of the tab stops, indents etc. to be left over from the
    previous import. Is there any way to apply the default document
    formatting before I import the next text file or do I have to manually
    remove all tab stops, indents, etc.?

    I think you can use:
    myIP.properties = myDoc.textDefaults.properties;
    although to be safe, you might be better off doing:
    myIP.paragraphs[0].properties = myDoc.textDefaults.properties;
    Actually, both seem to work.
    Dave

  • CS3 / javascript / Creating anchor frame and placing xml element

    Hi All,
    I have a problem with creating anchor frame, that is
    Actually i have created anchor frame, but it is not allowing to place the xml element, it shows "inline frame xml elements not allowed" some thing like this.
    I have handled anchor frame type is "custom" but it shows "inline frame".
    Any of you got better idea about this.
    regards,
    sudar.

    I believe this has to do with you doing a placeXML, where the XML contents does not match the tagged frames in the document.
    Again i'm not sure, but i dont think this has to do with what kind of frame you are placing into(inline or custom anchor) rather if your tagged frames and XML match up.
    Perhaps this link will help:
    http://forums.adobe.com/message/1111773

  • Create XML Element Tag BasedOn Found Character Style

    Hi,
    Good Day!
    Basically I want to search only for character styles that contains "ntb-", that is why it is hard coded in my searchString variable.
    Although I was able to create XML tag based on selected character style, but it will always add/insert at the end of the parent XML element.
    Can anyone could help me how insert/add that element at the insertion point where the text is found?
    Thanks,
    --elmer
    var myDoc = app.documents[0];
    myDoc.viewPreferences.horizontalMeasurementUnits = MeasurementUnits.POINTS;
    myDoc.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
    var charStyles = myDoc.allCharacterStyles;
    var foundStyles = Array();
    var searchString = String();
        searchString = 'ntb-';
    var tempName = String();
    var tempName1 = String();
    for(var i = 1; charStyles.length > i; i++){
       tempName = charStyles[i].name;
       tempName1 = tempName.toLowerCase();
       if(tempName1.indexOf (searchString.toLowerCase()) != -1){
           foundStyles.push (tempName);
    var myDialog = app.dialogs.add({name: "Convert Footnote Character Styles to XML Tags",canCancel:true});
    with (myDialog) {
        with (dialogColumns.add().borderPanels.add()) {
            with (dialogColumns.add()) {
                staticTexts.add({staticLabel: "Character style to search : "});        }
            with (dialogColumns.add()) {
                selCharStyle = dropdowns.add({stringList: foundStyles, selectedIndex: 0, minWidth: 175});
    var dialogShown = myDialog.show();
    while (dialogShown) {
        if (selCharStyle.selectedIndex == 0) {
            alert("Must have at least a character style to search!");
            dialogShown = myDialog.show();
            continue;
        } else {
            insertXMLTags(selCharStyle.stringList[selCharStyle.selectedIndex], selCharStyle.selectedIndex, "0");
            break;
    myDialog.destroy();
    alert("Finished!");
    exit();
    function insertXMLTags(cStyle, cStyleIndex, ip) {
        var myFinds = searchStyle(cStyle, cStyleIndex);
        for (i=myFinds.length - 1; i>=0; i--) {
            var myIP = myFinds[i].texts.item(0).insertionPoints.item(0);
            var myParentXML = myIP.associatedXMLElements[0];
            var myChiidXML = myParentXML.xmlElements.add ( cStyle );
            myChiidXML.contents =  myFinds[i].contents;
            //set the selection
            app.selection = myFinds[i].texts.item(0);
            //remove the selected text
            myFinds[i].texts.item(0).remove();
            Utility Functions         
    function searchStyle(cStyle, cStyleIndex){
        var myFinds;
        // if script version is for Indesign CS2
        if (app.scriptPreferences.version < 5){                                 
            app.findPreferences = NothingEnum.nothing;
            app.changePreferences = NothingEnum.nothing;
            myFinds = myDoc.search(undefined, undefined, undefined, undefined,
            {appliedParagraphStyle: pStyle, appliedCharacterStyle: cStyle});
        // else, for CS3 and CS4
        }else{                                 
            //Clear any existing find/change settings
            app.findTextPreferences = NothingEnum.nothing;
            app.changeTextPreferences = NothingEnum.nothing;
            // set character or paragraph style to search
            if (cStyleIndex != 0){ 
                app.findTextPreferences.appliedCharacterStyle = cStyle;
            //Set the find options.
            app.findChangeTextOptions.caseSensitive = false;
            app.findChangeTextOptions.includeFootnotes = true;
            app.findChangeTextOptions.includeHiddenLayers = false;
            app.findChangeTextOptions.includeLockedLayersForFind = false;
            app.findChangeTextOptions.includeLockedStoriesForFind = false;
            app.findChangeTextOptions.includeMasterPages = false;
            app.findChangeTextOptions.wholeWord = false;                             
            myFinds = myDoc.findText();
        return myFinds;

    Here is a way you can find any field.
    Download the current template.
    Open it in word and go to the line that you are interested in.
    The blanket PO# will be a field. Right click on it and go to properties. You will see the xml element there.
    Hope this answers your question,
    Sandeep Gandhi

Maybe you are looking for