Indesign Javascript and xml structure

Hi to all
I am new to program javascript in Indesign, and I am looking for some example on how modify the xml structure inside a document using a javascript script.
i.e.
if I have a structure like this in the original document:
root
section
tag1
tag2
tag3
I need to transform it in this way( this is just an example, may be more complex):
root
     section
          tag1
          tag2
          tag3
Any help on where or how to solve this is very appreciate.
Thanks a lot

I think the MoveXMLElement.jsx script there shows pretty well what's involved. Here's something that addresses something closer to your example:
var root = app.activeDocument.xmlElements[0];
root.xmlElements.item("tag1").move(LocationOptions.AT_END, root.xmlElements.item("section"));
root.xmlElements.item("tag2").move(LocationOptions.AT_END, root.xmlElements.item("section"));
root.xmlElements.item("tag3").move(LocationOptions.AT_END, root.xmlElements.item("section"));
You want to be careful about the order you do things and when you grab references to the xml structure objects, since you're changing them as you go (i.e. root.xmlElements[3] might refer to tag3 when you start, but will be invalid once you start moving things into section).
If the xml structure in your InDesign document is the result of an xml import, you might consider transforming the xml as you import it. It's faster and more natural there.
Hope that helps,
Jeff

Similar Messages

  • CDATA and XML structure

    Hej!
    I am trying to but an entire XML structure into a CDATA-tag. But have not been successful.
    Im using Xquery and trying to somthing like this:
    I have an variable $example which contains a XML structure. For example:
    $example = <elementA><A1>valueA1</A1><A2><A2a>text2a</A2a><A2b>text2b</A2b></A2><A3>valueA3</A3></elementA>
    I want to something like this <![CDATA[$example]]> to be expanded to <![CDATA[<elementA><A1>valueA1</A1><A2><A2a>text2a</A2a><A2b>text2b</A2b></A2><A3>valueA3</A3></elementA>]]>
    I have tried in many ways (eg by doing concat("<![CDATA[", $example, "]]>") ) and ended up with a CDATA tag that contains only the value of the elements in the tags of A1, A2 and A3. for example the CDATA that is created looks something like this:
    <![CDATA[valueA1text2atext2bvalueA3]]>
    instead of
    <![CDATA[<elementA><A1>valueA1</A1><A2><A2a>text2a</A2a><A2b>text2b</A2b></A2><A3>valueA3</A3</elementA>]]>
    I would really be grateful for any suggestions or tips and pointers on how to solve this.
    Best Regards
    Ninib
    Edited by: NinibEDB on 2010-nov-09 17:35

    Hi,
    Which XQuery processor are you using?
    According to the W3C specifications, the output of CDATA section is part of the serialization process, not the XQuery evaluation. So it's up to the implementor to provide the necessary options.
    The option we need here is the "cdata-section-elements" parameter :
    http://www.w3.org/TR/xslt-xquery-serialization/#XML_CDATA-SECTION-ELEMENTS
    For example, using the Saxon XQuery processor :
    declare option saxon:output "omit-xml-declaration=yes";
    declare option saxon:output "cdata-section-elements=test";
    let $example := "<elementA><A1>valueA1</A1><A2><A2a>text2a</A2a><A2b>text2b</A2b></A2><A3>valueA3</A3></elementA>"
    return <test>{$example}</test>which gives :
    <test><![CDATA[<elementA><A1>valueA1</A1><A2><A2a>text2a</A2a><A2b>text2b</A2b></A2><A3>valueA3</A3></elementA>]]></test>

  • Indesign Javascript, find  xml tag from cursor position

    Hi All,
    I have a single textframe with multiple xml tags within formated by paragraph and character styles.
    I want to access the xml tag attribute of the xmltag, related to my first 5 characters....
    How to do it?
    Or second approch, i need to find first and last xml tag on the page.

    Try this (second approach),
    Select any text frame and try the below code:
    alert(app.selection[0].lines[0].words[0].associatedXMLElements[0].markupTag.name)\\first XML tag
    alert(app.selection[0].lines[-1].words[-1].associatedXMLElements[0].markupTag.name)\\second XML tag
    Vandy

  • Structure inDesign document and export as XML for use in the web

    Hello everyone,
    I just recently started using inDesign and I am fascinated by its possibilities! I use it for a project where a finished inDesign layout that is used for a printed publication is now supposed to be transformed for implementing it on a web site. My job is to export the inDesign document as an XML file. After massive reading the last weeks I'm quite familiar with the structuring and tagging in inDesign. Though there's some issues I do not understand. Your precious advice would be of highest meaning to me
    The programmer who will later use my XML output for the web-transformation needs the document structured in different levels like "Root > Chapter > Subchapter > Text passage / table". I already structured the document with tags like title, text passage, table, infobox,... but the structure is just linear, putting one item following to another.
    How can I structure the document with reoccuring tags that enable me to identify the exact position of an item in the document's structure? So that I can say for example "text passage X" is located in chapter 4, subchapter 1. This has to be done because the document is supposed to be updated later on. So maybe a chapter gets modified and has to be replaced, but this replacement is supposed to be displayed.
    I hope my problem becomes clear! That's my biggest issue for now. So for any help I'd be very thankful!

    Our print publications are created in InDesign CS5 for Mac then the text is exported to RTF files then sent to an outside company to be converted to our XML specifications for use by our website developers.  I would like to create a workflow in which our XML tags are included in the InDesign layouts and then export the XML from the layouts.
    Some more detail about what kind of formatting is necessary might be helpful.
    I know that IDML files contain the entire layout in XML format.  Is it a good idea to extract what we need from IDML, using the already-assigned tags?
    Well, if you want to export the whole document, it's the only reasonable approach.
    We use a workflow system such that each story is a seperate InCopy document, stored in ICML format (Basically a subset of IDML). Our web automation uses XSLT to convert each story into HTML for use on our web site; it also matches it up with external metadata so it knows what is a headline and what is not, etc.. It is not exactly hassle free, and every once in a while someone uses a new InDesign feature that breaks things (e.g., our XSLT has no support for paragraph numbering, so numbered paragraphs show up without their numbers).
    You could do the same thing with with IDML, you'd just have to pick out each story, but that's small potatoes compared to all the XSL work you're going to have to do.
    On the other hand, there may be better approaches if you're not going to export the whole document. For instance,  you could use scripting to export each story as an RTF file, and then you could convert the RTF files into HTML using other tools.

  • Indesign Comparing XML Structure

    Can Anyone help me ?????
    I have wasted a lot time in this query with no result please help me to achieve my desired output.
    i want to display all XmlAttributes of a xml structure in a TextFrame of indesign CS4 that match the following conditions :-
    1) for a selected Character Style ( KT), XmlAttribute of one document(i.e CHAPTER ) must have same value as other document(GLOSSARY) that is being compared. then keywords with same id & olinkend would be displayed in a text frame.
    snapshot 1 shows chapter with highlighted keyterm & its olinkend (which to be used for comparison).
    snapshot 2 shows Xml Structure of Glossary with highlighted glossentry & its id
    Snapshot 3 shows Xml Structure of chapter(containing keyterm its olinkend)
    Snapshot 4 shows Xml Structure of chapter(containing glossary)
    in above snapshot pathology,etiology,pathogenesis,infection and disease have same olinkend(keyterm in chapter) and id (glossentry in glossary) but Human Microbiome Project  do not have different id & olinkend so its not a keyterm. it should not be displayed in text frame with  keyterms but somehow it is tagged wrongly as KT .we dont want it to b displayed.
    my text frame displayed it as
    i want a javascript code to display only keyterms in a text frame( in active document i.e. chapter )where keyterm olinkend = glossentry id and finally save the data to excel file .
    i have taken this code from ADOBE FORUM plz modify this to achieve my output.
    var myDc =app.activeDocument;
    var mySty = myDc.characterStyles.everyItem().name;
    var myDia = app.dialogs.add({name:"Character Style Display Menu", canCancel:true});
         with(myDia.dialogColumns.add()){  
              with(borderPanels.add()){
                   with(dialogColumns.add()){staticTexts.add({staticLabel:"Select Character Style:  "});}
                        with(dialogColumns.add())
                                                                var SelSty = dropdowns.add({stringList:mySty, selectedIndex:0});}
    var myRes = myDia.show();
    if(myRes==true)
          var myChoice = mySty[SelSty.selectedIndex];
                myDia.destroy();
    else
    { exit();}
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences.appliedCharacterStyle = myChoice.toString();
    var myFind = app.findText(false).reverse();
    for(var a=myFind.length-1; a>=0; a--){
         var  myString= myFind[a];
         var myPg = myString.parentTextFrames[0].parent.name;
         var myCon = myString.contents;
         app.selection[0].insertionPoints[-1].contents = String(myCon+"\t"+myPg);
         app.selection[0].insertionPoints[-1].contents = "\r";
    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
    if(myCon==null)
                                                      alert("Character Style not found");
    HOPE YOU WILL UNDERSTAND MY QUERY.
    THANX
    WAITING FOR REPLY.

    Could Peter or someone move this to the scripting forum, please?

  • XML structure validation by javascript

    Hi All,
    I’m trying to find solution for XML structure validation on opening the indesign document.
    Is this possible by javascript.
    by
    hasvi

    Or you could go directly to the source.
    http://help.sap.com/saphelp_nw70/helpdata/en/c4/e1343e8c7f6329e10000000a114084/frameset.htm
    Regards,
    Henrique.

  • Convert IDOC XML structure to flat file - and now?

    Hi,
    we are working with input message ORDERS05 and want to convert it to flat file.
    So we used the implementation description from "how to convert an IDOC-XML structure to a flat file....".
    Looks like this is a standard procedure described here fitting for all IDOCs.
    We followed the guide, making XI ready for Abap-Mapping, implemented the Abap class like described, added an interface mapping with source ORDERS05 to a mess.type dummy destination, added with type Abap-class the class implemented from the guide and completed the Int.Dir. implementation.
    For comparism purpose we have two systems as receiver, one with a standard flat file with regular graph.mapping in XI, one with the Abap mapping.
    Result:
    Error description in SXMB_MONI:
    Didn´t expect something like that! The IDOC was delivered successfully to the other simple flat file receiver.
    Any idea what we made wrong (we are on SP17) or if there is a standard mistake you can do when following the guide?
    Best regards
    Dirk

    Hi,
    I've got the same problem. He the solution in my case:
    The problem is:
    My IDOC has no element <STDMES>, but the method IF_MAPPING~EXECUTE from the 'HOW-TO Guide' does not check this situation:
    el_element = idocument->find_from_name('STDMES').
    ls_edidc-stdmes = el_element->get_value().
    thows the exception.
    Solution:
    make shure that the field STDMESis set or change the method to:
    el_element = idocument->find_from_name('STDMES').
    if not el_element is initial.
        ls_edidc-stdmes = el_element->get_value().
    endif.
    Best regards
    Dieter

  • How find the missing glyph using javascript [like indesign preflight], and replace same glyph available font or

    The situation:
    I want to use basetext font, but some of the glyphs are missing in it, and are highlighted with pink boxes. common font [stix, etc.] have much more glyphs than basetext font. I can apply common font [stix, etc.]manually for each of the missing glyphs or insert two character and use kerning set it up, but it is tedious.
    Question:
    How find the missing glyph using javascript [like indesign preflight], and replace same glyph available font or insert two character and use kerning set it up?
    Any one know how to do this?
    Thanks in Advance,
    ~Jack

    Try Peter kehrl's script
    http://www.kahrel.plus.com/indesign/missing_glyphs.jsx

  • InDesign and XML Automation

    I am new to the InDesign and XML Automation process.
    We have a xml file that has 100+ items and our goal is to automate them into a InDesign format (5-6 per page). Does InDesign/XML support this and what is the best approach to do this?

    The full script runs on "the active document", and it's possible that is the point where ID gets confused. Can you re-write it as a function with *one* parameter -- the document to work on?
    Then you can do your loopy (sorry) looping like this:
    someDoc = app.open(files[i]);
    Run("other script", someDoc);
    someDoc.close(SaveOptions.YES);
    "app.open" returns a handle to the ID document once it's opened, and if you save it into a variable you can use this wherever you are using "app.activeDocument" now.

  • RRI drilldown on structures using javascript and Web API

    Hi SDN community,
    We have devised a method to RRI on structure elements using javascript and Web API statements:
    var url = SAP_BW_URL_Get();
    zREP_UNIT_VAR1 = "ZN_MRU01";
    zREP_UNIT_VAR2 = "ZP_FPER";
    var zeroFISCYEARKey = getVar("ZPFYEAR");
    var zREP_UNITHierNodeKey = getVar("ZN_MRU01");
    var zREP_UNITHierNodeKey = trimString(zREP_UNITHierNodeKey);
    var zeroFISCPERVarKey = getVar("ZP_FPER");
    var zeroFISCPERKey = convertZeroFISCPERVarKeyToKey (zeroFISCPERVarKey);
    var zeroCURRENCYKey = getVar("ZPM_CURR");
    zREP_UNIT_TEMPLATE = "ZWT_CPERF_M50_UC_CHART";
    url = SAP_BW_URL_Get() + "&CMD=LDOC&TEMPLATE_ID=" + zREP_UNIT_TEMPLATE +"&VAR_NAME_1=" + zREP_UNIT_VAR1 + "&VAR_VALUE_EXT_1="  + zREP_UNITHierNodeKey  + "&VAR_NODE_IOBJNM_1=" + "0HIER_NODE" + "&VAR_NAME_2=" + zREP_UNIT_VAR2 + "&VAR_VALUE_EXT_2=" + zeroFISCPERKey + "&VAR_VALUE_EXT_3=" + zeroCURRENCYKey + "&CMD_1=DATA_PROVIDER%3DFY" + "%26FILTER_IOBJNM_1%3D"+ filter + "%26FILTER_VALUE_1%3D"  + parameter1 + "&CMD_2=DATA_PROVIDER%3DCMYTD" + "%26FILTER_IOBJNM_2%3D"+ filter + "%26FILTER_VALUE_2%3D"  + parameter1;
    SAPBWOpenWindow(url,"IO_Process_KPI_Report","width=screen.width, height=screen.height,menubar=yes, toolbar=no, scrollbars=yes, resizable=yes");
    Necessary conditions:
    The same Global Structure is in the Sender Query and the Target Query
    Question:
    Is there any other way to RRI on structure elements within a sender query to a target query using:
    BADI's, ABAP or any other method.
    Thank you.
    Simon

    Hi SDN Community,
    At the time of asking this question there were not many examples of BADI for RRI's.  I now see a number of examples we can use.
    Thank you.
    Simon

  • Book about InDesign and XML

    Hello everybody!
    Has anybody read "A Designer's Guide to Adobe InDesign and XML" by James J. Maivald, Cathy Palmer (Adobe Press)? I am looking for a book about using xml in InDesign. And i'm hoping the title says it all: a guide to show me the basics. Or does anybody have another book I should read?
    Thank you for answering!
    Maaike

    It is a great book to begin for inDesign and XML.
    Strange enough there is NO mentioning at all of how to process tabels!
    Maaike, if you are Dutch take a look here:
    http://www.macmojo.nl/nl/artikelen/gratis-hoofdstuk-als-pdf-van-het-nieuwe-boek-slimmer-we rken-met-indesign-cs4.html

  • XML structure and FCC parameters

    Hi Experts,
    Kindly help me with the XML structure and  FCC parameters for the following sample of text file
    I am new to Text Files and FCC.
    =================================================================================
    Header
    " name of the company " ,1   
    " abc 2,10/01/1972",4
    Line items
    "ADFERT",KARNATAKA,CHIPS,G,45.560000,72.190000,100.983000,76.266000,J
    "GHTJEN",KERALA,BANANAS,G,1.135000,0.714850,1,0.755000,J
    Trailer
    DDDDDDDDD,B
    ================================================================================
    It is a CSV
    Header 1st line , first field is Variable length and 2nd field is 1 char
    Header 2nd line , first field is Variable length and 2nd field is date and last field is 1 char
    Line items
    first field fixed length 6 char but
    2nd field can be of any length
    3rd field can be of any length
    4th field 1 char
    5th field can be of any length
    6th field can be of any length
    7th field can be of any length
    8th field can be of any length
    9th field 1 char
    and then the Trailer
    Please help in the structure and content conversion parameters
    also following questions :
    a)  I have to pick up this file and pass to a proxy in AbAP on target side , so do i just create a service interface and in ECC --> Sproxy and identify my SI and do a Create Proxy ? or is there anything else required ?
    b) The Date in the header needs to be passed onto ECC as a parameter so in my XML structure in the data type do i include that as a field in the mapping ..Can any one please guide me to create the Data type structure for the above file ?
    c) DO I NEED A MAPPING FOR THIS ?? THERE ARE NO CONVERSIONS required ? what are the IR and ID steps required
    if it is a FILE to Proxy scenario with no mappings 
    Please help
    thanks
    Dev

    Hi Dev,
    Full Data type is as follows
    Sender_DT
    order_recordset  0..1
    order_header                 0..1
      header-1    0..1
      date            0..1
    order_Item                      0..unbound
      item-1          0..1
      item-2          0..1
      item-3          0..1
      item-n          0..1
    order_Trailer                    0..1
      trailer-1  0..1
      trailer-2  0..1
      trailer-n  0..1
    > What about the File Content conversion parameters , can you help me with those
    order_header.fieldNames     : f1,date
    order_header.fieldSeparator : <give the fiels separater , [if it is comma])
    order_header.endSeparator   : 'nl' (if it is new line characters)
    order_item.fieldNames     : i1,i2,.....
    order_item.fieldSeparator : :
    order_item.endSeparator   : 'nl'
    order_Trailer.fieldNames     : t1,t2,.....
    order_Trailer.fieldSeparator : :
    order_Trailer.endSeparator   : 'nl'
    If any of the two structures (header, item or trailer) in the field name is same then we have to use the key field
    Check this link
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417600)ID1157374550DB11273870171440820710End?blog=/pub/wlg/3228
    > b) In FCC what will be the values for fieldnames ?
    Check this link
    https://wiki.sdn.sap.com/wiki/display/XI/XI_File_Content
    Regards
    Ramesh

  • Remove Structured Anchored Frame  without disturbing the XML Structure - Reg.

    Dear All,
    Please any one help me!, How to remove the xml Structured Anchored Frame without disturbing the XML Structure.
    Manually If I'm removing the XML Structured Anchored Frame, the XML Structured is gone.
    I tried so many ways.  If  I am removing manually in Grouped Frame, then this problem is not happens.
    I mean, Create 2 separate frames Move any xml structured contents to that frames. Group that 2 frames and make it anchored.
    Now you can remove that anchored, this xml Structure is not disturbing (I mean not removed).
    If I did the same in above method for Single Text Frame, this xml Structure is gone.
    Kindly any one person resolve this problem, Thanks in advance!!!
    Note:
    (1) I tried through in InDesign CS6 Plug-In, this is working perfectly. But I need in Javascript to do this.
    Thanks & Regards
    T.R.Harihara SudhaN

    Hm – if you can do it with a Group object, why don't you wrap around a group object?
    With ExtendScript it's quite possible to create Groups with only one single object.
    If we have a text frame selected, you could add a "helper" rectangle to the spread.
    Group the text frame and the rectangle, then remove the rectangle from the group.
    Now you have a Group with a single text frame.
    var myTextFrame = app.selection[0];
    var myHelperRectangle = app.documents[0].layoutWindows[0].activeSpread.rectangles.add();
    var myGroup = app.documents[0].layoutWindows[0].activeSpread.groups.add([myTextFrame,myHelperRectangle]);
    myGroup.rectangles[0].remove();
    app.documents[0].select(myGroup);
    Uwe

  • Fetch entire xml structure

    Hi,
    I am looking for a way to get the entire xml structure inside an actual xml object, or if possible, as a string. I need to pass it to a service but i haven't found a way to get it in the layout that it is shown in the structure panel. The only thing i am able to do is work with XMLElments but isnt there any other way to access it?

    if its importing then you can import the xml into javascript rather than indesign then manipulate the xml before placing it in indesign.
    for example, in this case the xml is read from a file into javascript:
    var xmlFile = File.openDialog ("Please select the XML file");
    xmlFile.open("r");
                        var strXML = xmlFile.read();
      xmlFile.close();
                        XML.ignoreComments = true;
                        XML.ignoreProcessingInstructions = true;
    xmlTree =  new XML(strXML);
    var childrenXML = XMLTree.children(); // children would be directly below the root element to select individual elements use .child("elementName") there are several other options available for navigating through the nodes: including: .parent() and also descendants().
    for (i =0;i < XMLTree.children().length; i++) {
    //process the xml
    Keith

  • [CS3 JS] Is it possible to export just the XML structure?

    Hello,
    I am using scripts to find various objects in an InDesign document and tagging them.
    I will then want to export the XML structure but not any of the content. I'm just learning XML and do not see a way to do this.
    Thanks,
    Tom

    Share/export using QuickTime to an audio only codec such as MP3.

Maybe you are looking for