4 Replies Latest reply on Dec 22, 2008 10:34 PM by Adobe-InDesign CS4

    Prevent untag() children

      Suppose I have in my InDesign XML tree:<br /><contentA>1. <br /><contentB>Some content here.</contentB> <br /></contentA><br /><br />If I right click on <contentA> in the tree and choose "Untag Element", <contentA> goes away and <contentB> remains untouched.<br /><br />However, if in the tree I have <contentA> selected, and I run:<br />app.selection[0].untag();<br />then both <contentA> and <contentB> are untagged.<br /><br />Both are also untagged if I:<br />app.selection[0].xmlElements.item(0).parent.untag();<br /><br />How can you untag a parent element and leave its children untouched using Javascript?<br /><br />Thanks!
        • 1. Re: Prevent untag() children
          [Jongware] Most Valuable Participant
          Perhaps because you are untagging a selection (and thus everything inside it)? Apparently, the UI defaults to using the XML elements, not the text selection.

          XMLElement has a function "untag", which states

          >void untag ()
          >Untags an element.

          so you have to find the outer XML element somehow.
          • 2. Re: Prevent untag() children
            Level 1
            I found that with element(s) selected in the tree, this script works perfectly...

            var myMenuAction = app.menuActions.item("$ID/Untag Element");
            try {myMenuAction.invoke();}
            catch (err){};
            • 3. Re: Prevent untag() children
              subhaoviya Level 1
              this not works in indesign cs2, i got an error as "app not has a property or method as .menuActions", how to handle this in indesign cs2?

              --thanks in advance
              subha
              • 4. Re: Prevent untag() children
                Adobe-InDesign CS4 Level 1
                Dear Subhaoviya,<br /><br />  Currently we can't get the "menuActions methods" in CS2. So we are able to indirectly use for what you expect.<br /><br />for your query :<br />  <contentA>1. <br /><contentB>Some content here.</contentB> <br /></contentA><br /><br />You need :<br />     <contentB>Some content here.</contentB> -> untag <br /><br />Your Answer :<br />       Some content here. <br /><br /> Like that? then here the below coding, you can use.<br /><br /> /** before you catch the XML Elements of the correct element **/<br />    var y = app.selection[0].characters.length;<br />    app.select(elm.xmlElements[i].characters[0], SelectionOptions.replaceWith);<br />   app.select(elm.xmlElements[i].characters[y-2], SelectionOptions.addTo);<br />   app.select(elm.xmlElements[i].texts); <br />   elm.xmlElements[i].untag(); <br /> <br />  // *now you get the untaged value of the currect Element.*//<br /><br />Please let me know if you have any queries.<br /><br />Thanks & Regards<br />T.R.Harihara SudhaN