Apply an existing XML Tag To Current Object JS (JavaScript)

I'm working on a JavaScript to automatically tag the currently-selected object.
I first check to see if the desired tag already exists -- if not I create it:
          var myXMLElement = myDocument.xmlElements[0].xmlElements.add(tagType);
Then assign it to the currently-selected object:
          mySelection.markup(myXMLElement);
This works fine.
However, if the desired tag ALREADY EXISTS, I'm having problems.  I haven't been able to figure out how to reference the existing element with the markup call.
Can someone help me with how to do this?
Thanks much!

That didn't quite work for me...but it put me in the right direction.  I think I have it working with this snippet:
     myDocument.xmlElements[0].xmlElements.add(tagName, mySelection);
Thanks much for your help!
--Aaron

Similar Messages

  • [JS][CS4-5] Apply hyperlink to xml tagged object

    Hi,
    Can anyone please help me? I'm strugling with this problem for days....
    I'm trying to apply a new hyperlink to a xml tagged object (piece of text, frame or image)...
    The script trows an error "wrong source. Expected text but received XML element"
    Does anyone know how i can fix this?
    Thanks
    Code:
    var myDoc = app.documents[0];
    Check(myDoc.associatedXMLElement);
    alert("Done !");  
    //recursive function
    function Check(elm){
             for(var i=0; i<elm.xmlElements.length; i++){
                   myXMLElement = elm.xmlElements[i];
                   XMLelementName = myXMLElement.markupTag.name.toString();
                   // only apply to tagged object using the tag "Hyperlink"
                   if (XMLelementName == "Hyperlink"){
                          var myHyperlinkURL = myDoc.hyperlinkURLDestinations.add("http://www.google.com");
                          myHyperlinkURL.name = "http://www.google.com";
                          var myObject = elm.parent;
                          if(!( elm.xmlAttributes.item("href") == null)){
                                    // it's a picture
                                   // i'm not sure this will work
                                myHyperlinkSource = myDoc.hyperlinkPageItemSources.add(myObject);                 
                          }else{
                                   // it's not a picture
                                  // Error is in the line below
                                myHyperlinkSource = myDoc.hyperlinkTextSources.add(myObject);                 
                          var myHyperlink = myDoc.hyperlinks.add(myHyperlinkSource, myHyperlinkURL);
           // process all sub elements
           for (var i = 0; i < elm.xmlElements.length; i++){
                Check(elm.xmlElements[i]);

    Hi,
    Thanks for your feedback.
    Due to your great feedback, I've made some changes to the line below...
    var myObject = elm.texts[0];
    When performing the script, a hyperlink is added to all text in the textframe, not only to the text tagged by the xml tag. Does anyone know how this can be fxed?
    Also, when trying to do the same thing for  an image, but this doen't work...
    var myObject = elm.images[0];
    An error occures.
    And what about a empty graphic frame ? How can I add a hyperlink to frame if it's tagged by a certain xml tage?
    Any feedback would be helpfull...
    Tim

  • Map XML tag to an object style

    Hi everyone!
    I am not sure this is the correct place to post it, but i didn't find any "tagging" department of the forums.
    I do import some XML into ID document.
    Text nodes of my XML are imported properly, and i can map any tag of XML to one of the paragraph or table styles.
    But, when i import any images (or another ID documents) with <... href="..." />, how can i map that tag to an object style?
    ///////////// It would be very helpful for example when i'm going to set the stroke of 1pt to all of inline images of text frame.
    Please any feedback would be helpful.
    Alex.

    I will try to give an example, just to give a kick start ........... you need little bit of tweaking to meet your actual requirement:
    suppose you have an xml element "tag" having an attribute "@href" with object style name defined as  it's value. 
    <tag href="object_style_name">
    "object_style_name" is a object style and should exist in your document. To map the tag with the corresponding object style value you can use XMLRules in JS:
    //NOTE: NOT TESTED, BUT SHOULD WORK
    #include "glue code.jsx"
    main();
    function main(){
    if (app.documents.length != 0){
    var myDoc = app.activeDocument;
    var myRuleSet = new Array (
    new findObjAttribute("//*[@href]")
    with(myDoc){
    var elements = xmlElements;
    __processRuleSet(elements.item(0), myRuleSet);
    else{
    alert("You have no document open!");
    exit();
    function findObjAttribute(XPATH){
    this.name = "findObjAttribute";
    this.xpath = XPATH;
    this.apply = function(myElement, myRuleProcessor)
    //Just to check whether the collect element is selected
    var elmName=myElement.markupTag.name;
    var styleName=myElement.xmlAttributes.itemByName("href").value;
    with(myElement){
    try {
    applyObjectStyle(myDoc.objectStyles.item(styleName), true);
         } catch(e){};
    return true;
    HTH,
    Pankaj Chaturvedi

  • [CS5 JS] Problem in Applying character styles xml tag names

    Hi,
    e.g. 1
    <italic>This is a italic text with <sup>superscript value</sup></italic>
    e.g.2
    <sup>This is a superscript text with <bold>Bold superscript</bold></sup>
    <italic>  mapped to character style "italic" and
    <sup> mapped to character style "sup"
    In my java script I already mapped the xml tags to specific character styles. In some of the cases (see e.g.1 and e.g.2) I need to map it to other character styles.
    In e.g.1 I need to apply a new character styles "italicSup" for the text "superscript value" same way
    In e.g.2 I need to apply a new character styles "BoldSup" for the text "Bold superscript".
    Can any know how to do this?
    Green4ever

    FYI, I am using
    Win Xp-SP2, CS5 7.0.3

  • [CS3 JS] How to associate text with an XML tag

    Hello,
    I have a script that allows one to create or modify an XML tag after one selects text, a text frame or an existing XML tag. It works fine for making the XML tag but it does not associate the text or text frame to the tag. To do that I have to right click on the selection and use the context menu to Tag Text or Tag Frame.
    I want to make this automatic but cannot see how to script it.
    Thanks for any help

    I figured out the problem (which of course creates other interesting problems).
    In the line:
    var elementRef = rootElement.xmlElements.add (tagRef);
    I forgot to add a reference to the xmlContent. It should read:
    var elementRef = rootElement.xmlElements.add (tagRef, whatToTag);
    However, this script is designed to create a dialog box where one can either create a tag along with attributes or edit an existing one. I'll post it when I am done, but there is one hangup. The script not only changes the name of a selected xml tag but all tags with the same name. How can I get it to change only the selected tag? Below is the boiled down script that duplicates that problem.
    Thanks,
    Tom
    var myDoc = app.activeDocument;
    var selObj = app.selection[0];
    var TagIWantToChange = selObj.markupTag;
    var newTagName = "PleaseWork"; //This line replaces all the coding to create a dialog box where the tag name could be edited.
    TagIWantToChange.name = newTagName;

  • [CS3][JS] Apply XML tag for selected text

    Hi
      I need to apply XML tag to selected text in a tagged content.The XML tag is already applied for paragraph.I need to apply XML Tag for selected text in a paragraph.
    I have used following code, it applies tag for entire paragraph,not a selected text in a paragraph.
    app.selection[0].associatedXMLElements[0].markupTag=myDoc.xmlTags.item("italic");
    Please suggest me.
    Regards
    kumar

    The example script, markup.jsx
    //Markup.jsx
    //An InDesign CS4 JavaScript
    //Shows how to use the markup method.
    main();
    function main(){
        mySetup();
        mySnippet();
        myTeardown();
    function mySetup(){
        var myDocument = app.documents.add();
        var myPage = app.activeWindow.activePage;
        var myRootXMLElement = myDocument.xmlElements.item(0);
        var myXMLTag = myDocument.xmlTags.add("xml_element");
        var myXMLElementA = myRootXMLElement.xmlElements.add(myXMLTag);
        myXMLElementA.contents = "This is a paragraph in an XML story.";
        var myTextFrame = myPage.textFrames.add({geometricBounds:myGetBounds(myDocument, myPage)});
        myTextFrame.contents = "This is the first paragraph in a text frame.\rThis is the second paragraph in a text frame.\rThis is the third paragraph in a text frame.\rThis is the fourth paragraph in a text frame.\r";
    function mySnippet(){
        //<fragment>
        var myDocument = app.documents.item(0);
        var myPage = myDocument.pages.item(0);
        myDocument.xmlElements.item(0).xmlElements.item(0).markup(myPage.textFrames.item(0));
        //</fragment>
    function myTeardown(){
    function myGetBounds(myDocument, myPage){
        var myPageWidth = myDocument.documentPreferences.pageWidth;
        var myPageHeight = myDocument.documentPreferences.pageHeight
        if(myPage.side == PageSideOptions.leftHand){
            var myX2 = myPage.marginPreferences.left;
            var myX1 = myPage.marginPreferences.right;
        else{
            var myX1 = myPage.marginPreferences.left;
            var myX2 = myPage.marginPreferences.right;
        var myY1 = myPage.marginPreferences.top;
        var myX2 = myPageWidth - myX2;
        var myY2 = myPageHeight - myPage.marginPreferences.bottom;
        return [myY1, myX1, myY2, myX2];
    I think you can use the markup function on the selected item (Text Object have a markup method)
    Thomas B. Nielsen
    http://www.lund-co.dk

  • JS to change object XML tag

    Hi
    any one knows how to change a tagged object's XML tag from say Aold to Bnew without affecting it's content and position in the XML structure?
    Thank you

    Hello. I'm new here but it seems to be the only place where I can post this question to.
    I'm working in a C# application that uses InDesign CS3 scripting. I'm trying to create an index automatically from a tabbed list of words in a text file.
    As C# is a strongly typed language, I have to cast all objects to the right type. I'm having problems when I try to add the page numbers to the created index entries using the following code (I've used the CreateIndexEntry.jsx scrip as a starting point).
    //Find all occurrences of the word or set of words (the topic name)
    ((InDesign.FindTextPreference) app.FindTextPreferences).FindWhat = topic.Name;
    InDesign.Objects foundTexts = doc.FindText(System.Reflection.Missing.Value);
    It's supposed to be an Array of Text objects (InDesign.Text) but when I try to cast each object using this
    //Code is forced because I've tried everything here
    //Loop through each finding and add page numbers to topic
    IEnumerator textEnum = foundTexts.GetEnumerator();
    while (textEnum.MoveNext())
    object text = textEnum.Current;
    topic.PageReferences.Add((InDesign.Text)text, InDesign.idPageReferenceType.idCurrentPage, System.Reflection.Missing.Value, System.Reflection.Missing.Value);
    I got the following exception (translated).
    text is not an InDesign.Text object (Interfaces doesn't match)
    So the question is what object type should I use to cast each object resulting by calling the Document's FindText method.
    Every suggestion will ve very welcome.
    Thank You very much.

  • How to add tags to the existing XML file?

    Hi,
    I have a requirement wherein I have to add a tag to the existing xml data.
    For Eg:
    <ROW>
    <EVNT_ID>7333976</EVNT_ID>
    <DISTRCT_CD>67</DISTRCT_CD>
    <TIME_OFF>06-May-2008 10:50:04 AM</TIME_OFF>
    </ROW>
    The desired output is,
    <DI_DATA>
    <ROW>
    <EVNT_ID>7333976</EVNT_ID>
    <DISTRCT_CD>67</DISTRCT_CD>
    <TIME_OFF>06-May-2008 10:50:04 AM</TIME_OFF>
    </ROW>
    </DI_DATA>
    I have to add <DI_DATA> </DI_DATA>at the start and end of the input.
    Could any of you help me on this?
    Thanks,
    GV

    If your XML is just in a CLOB, you can just use string manipulation to prepend/append the nodes on. If you have it in an XMLType you could just do the following
    select appendchildxml(XMLTYPE('<DI_DATA/>'),
                                  'DI_DATA',
                                  XMLTYPE('<ROW>
    <EVNT_ID>7333976</EVNT_ID>
    <DISTRCT_CD>67</DISTRCT_CD>
    <TIME_OFF>06-May-2008 10:50:04 AM</TIME_OFF>
    </ROW>'))  -- this would be your variable
      from dual;which will put your data within the DI_DATA node.

  • How to apply paragraph styles to xml tag?

    Hi All,
    How to apply paragraph style to xml tag?

    Hi Learner,
    Try the below js code.
    var myDoc = app.activeDocument;
    try{
        mySel=app.selection[0];
        myDoc.xmlElements[0].xmlElements.add({markupTag:"TEST", xmlContent:mySel});
        }catch(e){
            alert(e);
    var myDocument = app.activeDocument;
    app.findGrepPreferences.appliedParagraphStyle = "test";
    app.findGrepPreferences.findWhat = ".+(?=\\r)"
    var mySearch = myDocument.findGrep(false);
    for (a=0; a<mySearch.length; a++){
        myDocument.xmlElements[0].xmlElements.add({markupTag:"TEST", xmlContent:mySearch[a]});
    thx,
    csm_phil

  • Count how many XML tag existed

    I am new in BI publisher and hope someone can give me some help. I need to display an invoice number and term-sequence_number. If the invoice number has only 1 term_sequence_number, just display the invoice number. However, if the invoice has 2 or more term_sequnce_number, display invoice number then the term-sequence_number. For exampe
    <LIST_G_INVOICE>
    <G_INVOICE>
    <INVOICE_NUMBER>123456</INVOICE_NUMBER>
    <WHATEVER>35345</WHATEVER>
    <LIST_G_INV_TERM>
    <G_INV_TERM>
    <TERM_SEQUENCE_NUMBER>1</TERM_SEQUENCE_NUMBER>
    <AMOUNT>100.39</AMOUNT>
    </G_INV_TERM>
    <G_INV_TERM>
    <TERM_SEQUENCE_NUMBER>2</TERM_SEQUENCE_NUMBER>
    <AMOUNT>482435</AMOUNT>
    </G_INV_TERM>
    <G_INV_TERM>
    <TERM_SEQUENCE_NUMBER>3</TERM_SEQUENCE_NUMBER>
    <AMOUNT>3848</AMOUNT>
    </G_INV_TERM>
    </LIST_G_INV_TERM>
    </G_INVOICE>
    in my example, this invoice will have 3 sub invoice. The first subinvoice will have invoice number 123456=1. The second subinvoice has 123456=2 and third subinvoice has 123456=3 . however, if there is only ONE TERM_SEQUENCE_NUMBER, the subinvoice invoice ( well there is only one anyway ) will be 123456
    I am currently in G_INV_TERM group. I have the following
    <?../../INVOICE_NUMBER?><?if:count(TERM_SEQUENCE_NUMBER)>1?>
    =<?TERM_SEQUENCE_NUMBER?>
    <?end if?>
    But so far, the condition is always false and the count(TERM_SEQUENCE_NUMBER) always return 1 even i have 3 TERM_SEQUENCE_NUMBER xml tag
    How can I return the condition so, in my example, it will return ture and the total count of TERM-SEQUENCE_NUMBER is 3

    I'd use something like this :
    select t.gcssmc_imports_data_id
         , count(*)
    from gcssmc_imports_data t
       , xmltable(
           xmlnamespaces('http://www.usmc.mil/schemas/1/if/stratis' as "p0")
         , '/p0:salesorderOutCollection/p0:salesorderOutRecord'
           passing xmltype(t.rec_data)
         ) x
    where t.interface_name = 'MATS'
    and t.status = 'COMPLETED'
    group by t.gcssmc_imports_data_id
    ;

  • Find XML Tags then apply para style

    Hi everyone,
    I need your help for find xml tags and apply para graph style in InDesign CS2. We have 200 xml files apply only 7 type of paragraph styles so any one help and any JS/Apply script or any other find and replace method. I am really appreciate of my bottom of heart.
    thank you so much.

    Hi,
    Try:
    #include "../XML Rules/glue code.jsx";
    var myDoc = app.documents.item(0);
    var myRuleSet = new Array (new applyParaStyle());
    with(myDoc){
            var elements = xmlElements;
            __processRuleSet(elements.item(0), myRuleSet);
              function applyParaStyle(){
                        this.name = "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");
                        default:                   
                        break;
                                  return true;

  • IDOC to File, variable substitution on outbound message XML tag attributes

    My scenario is IDOC to FILE using XSL mappings.The target format is 2 XML tags (header, line) with the data stored in the attributes of each tag.
    EG. <header attr1=one attr2=two attr3=three><line attr1=one attr2=two /></header>
    The name of the file is dictated by an outbound attribute value in the header tag.
    Can I get access to it the attribute in the target message in the CC_FILE using variable substution. ?
    Currently I am not using content conversion as the XSL produces the file format needed, so I would pefer not to change the outbound message format/structure as this is going to an external party. I would prefer not to change the outbound format as this would need content conversion to strip the unwanted/information/processing node that is used for this purpose (file naming).
    The name is a calculation of fields in the IDOC and is not explicit dictated (business logic is applied in the mapping to get the file name), so I would prefer to use the attribute of the resulting XML to keep the "business logic" in the XSL..
    Things that cannot be changed.... 1. Must use XSL.for mapping. 2. Format cannot be changed of the outbound message. 3. Would prefer not to involved content conversion to keep formatting/node structure in the XSL mapping.
    I have seen some reference to this being possible on the forums but nothing solid from what Ive read.
    Something like var1 = payload:/Header/@attr1 in variable sub to get at the attribute
    Any comments ?
    Thanks in advance.
    One final piece of info. its on a PI 7.1 system.

    I think its best explained by my other thread Link:PI 7.1 Access to Dynamic Configuration through Java Class .
    Thanks for the link I have already implemented based on that link but the one crucial difference is that it is implemented using a static method with no reference to the actual object (payload) for Dynamic configuration. It seems that without the 7.0 API which isnt available in 7.1 by default XSL with java extentions is limited to static methods. If you could read the other thread it certainly is possible I'm mistaken.

  • Generation of XML file from Java objects using castor

    I have the following java file(Customer.java).
    public class Customer
         private String ID;
         private FirstName firstName;
         private MiddleName middleName;
         private LastName lastName;
         private ArrayList address;
         public ArrayList getAddress() {
              return address;
         public void setAddress(ArrayList address) {
              this.address = address;
         public FirstName getFirstName() {
              return firstName;
         public void setFirstName(FirstName firstName) {
              this.firstName = firstName;
         public String getID() {
              return ID;
         public void setID(String id) {
              ID = id;
         public LastName getLastName() {
              return lastName;
         public void setLastName(LastName lastName) {
              this.lastName = lastName;
         public MiddleName getMiddleName() {
              return middleName;
         public void setMiddleName(MiddleName middleName) {
              this.middleName = middleName;
    Using castor i have created an xml file(customer.xml) which has the following format.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <customer ID="fbs0001">
    <FIRSTNAME>Fred</FIRSTNAME>
    <MIDDLENAME>B</MIDDLENAME>
    <LASTNAME>Scerbo</LASTNAME>
    - <ADDRESS>
    <FIRSTLINE>No 18, Sheshadri road</FIRSTLINE>
    <SECONDLINE>Gandhinagar Bangalore</SECONDLINE>
    </ADDRESS>
    - <ADDRESS>
    <FIRSTLINE>ITPL</FIRSTLINE>
    <SECONDLINE>Whitefield Bangalore</SECONDLINE>
    </ADDRESS>
    </customer>
    I have used a mapping file to get this output.Is there a way where i can get the output xml in the following format without changing the Java object structure.If yes then please suggest how this can be done.
    <?xml version="1.0" encoding="UTF-8" ?>
    - <customer ID="fbs0001">
    <FIRSTNAME>Fred</FIRSTNAME>
    <MIDDLENAME>B</MIDDLENAME>
    <LASTNAME>Scerbo</LASTNAME>
    </customer>
    <ADDRESS>
    <FIRSTLINE>No 18, Sheshadri road</FIRSTLINE>
    <SECONDLINE>Gandhinagar Bangalore</SECONDLINE>
    </ADDRESS>
    - <ADDRESS>
    <FIRSTLINE>ITPL</FIRSTLINE>
    <SECONDLINE>Whitefield Bangalore</SECONDLINE>
    </ADDRESS>
    I mean the output xml file should have the address as a separate tag not withing the root tag customer.

    Hello,
    Castor's own discussion groups might be able to point you to the solution you're looking for (if this use case is possible using Castor).
    Oracle has its own object-to-XML mapping tool that is part of the TopLink product. It allows you to map existing objects to an existing XML Schema. This can be done visually using the TopLink Workbench, or programmatically using the TopLink APIs. TopLink OXM also supports the JAXB specification.
    Using TopLink OXM to get the desired XML result I would recommend the following. Map the Customer and Address classes to XML, but don't map the relationship between Customer and Address. Then make the calls to the marshaller something like the following:
    marshaller.marshal(aCustomer, System.out);
    for(int x=0; x<aCustomer.getAddress().size(); x++) {
         marshal(aCustomer.getAddress().get(x), System.out);
    Example - Using TopLink OXM to map an existing object model to an existing XML Schema:
    http://www.oracle.com/technology/products/ias/toplink/preview/10.1.3dp4/howto/ox/index.htm
    For more information on TopLink object-to-XML mapping:
    http://www.oracle.com/technology/products/ias/toplink/preview/10.1.3dp4/objectxml/index.html
    -Blaise

  • Auto mapping of Columns to custom XML tags

    Hello:
    I would like to build interface to my Oracle database. Instead of exposing the column names, I would like to translate them to business-savvy XML tags. Of course, I can do this by using the AS construct in my SELECT statements.
    I would like to know whether there exists any advanced features in Oracle that automatically do this function.
    Thank you.
    Venkat

    Once you the get the output in xml format from oraext:query-database function you can apply an xsl function to transform it and do the required.

  • Adobe InDesign CS5 Server JavaScript: Get rectangle by XML tag

    Hi,
    Current set-up:
    Adobe InDesign Server CS5 scripted through ExtendScript via PHP SOAP
    The problem:
    I'm currently placing an image file into a rectangle using the following code:
    frame     =   doc.rectangles[0];
    imgList   =   frame.place(new File(img));
    This works fine; the img file is placed into the rectangle as expected. However, this only refers to the first rectangle in the document: if I have two rectangles in the document, the image is placed into the last created rectangle.
    What I'd ideally like to be able to refer to the rectangle by its XML tag - something like:
    frame     =   doc.getRectangleByTag('Pic'); // <Pic> being the name of the XML tag
    imgList   =   frame.place(new File(img));
    Does anyone have any advice as to how this can be achieved? I realise this is rudimentary question, but am finding no joy after several hours of searching.
    Many thanks

    What I'd ideally like to be able to refer to the rectangle by its XML tag - something like: 
    frame     =   doc.getRectangleByTag('Pic'); // <Pic> being the name of the XML tag
    imgList   =   frame.place(new File(img));
    Are you sure you want to do it this way?
    Could you explain why? I suspect there is a better solution.
    In any case, at least in my test case, the XML tag is associated with the image inside the frame and not the frame itself. So if you want the frame, you must get the image associated with the tag and then go up to the parent. This works in a simple test:
    var frame =
        app.activeDocument.xmlElements[0].
        evaluateXPathExpression("//tennis")[0].
        graphics[0].parent;
    [object Rectangle]

Maybe you are looking for