Skip to main content
Inspiring
August 8, 2017
Answered

Add XML Elements with the attributes using Find pallete

  • August 8, 2017
  • 1 reply
  • 689 views

Hi,

     We can add XML Elements using Find and Replace palette.  Can we add with attribute name and values while adding the xml elements?? If not can capture the element which added using changeText for each occurrence to add attributes??

    

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;;                        

app.findTextPreferences.appliedCharacterStyle = "emph";

app.changeTextPreferences.appliedCharacterStyle = "emph";

app.changeTextPreferences.markupTag = "emphasis";          // Add xml Tag

var res1 = app.activeDocuemnt.findText();

if(res1.length > 0)

{

     app.activeDocument.changeText()

}

- Sudha K

This topic has been closed for replies.
Correct answer Chinnadk

Try this,

var doc = app.activeDocument;

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = "emph";

app.changeTextPreferences.markupTag = "emph";

var res1 = doc.findText();

if(res1.length > 0)

{

        for(var i=0;i<res1.length;i++)

        {

                res1.changeText();

                res1.findText()[0].insertionPoints[0].associatedXMLElements[0].xmlAttributes.add("name","value");

            }

    }

app.findTextPreferences = app.changeTextPreferences = null;

Regards,

Chinna

1 reply

Sudha_KAuthor
Inspiring
August 9, 2017

Can anyone help me...

Chinnadk
ChinnadkCorrect answer
Legend
August 9, 2017

Try this,

var doc = app.activeDocument;

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.findWhat = "emph";

app.changeTextPreferences.markupTag = "emph";

var res1 = doc.findText();

if(res1.length > 0)

{

        for(var i=0;i<res1.length;i++)

        {

                res1.changeText();

                res1.findText()[0].insertionPoints[0].associatedXMLElements[0].xmlAttributes.add("name","value");

            }

    }

app.findTextPreferences = app.changeTextPreferences = null;

Regards,

Chinna

Sudha_KAuthor
Inspiring
August 10, 2017

Hi,

          Thank you... Its working...

          when i am finding contents ' (single quote) in find palette sometimes its returing ' (quote as symbol) but in sometimes its retuning STRAIGHT_SINGLE_QUOTE.  How to find this character in document?

     When quote is with other characters its returning contents correctly (as symbol) but when it comes alone and sometimes its returning STRAIGHT_SINGLE_QUOTE or corresponding number for quote. I am assigning selection contents to find. How can i find the single and double quote when find using selection contents?

        app.findTextPreferences = app.changeTextPreferences = null;

        app.findTextPreferences.appliedCharacterStyle = cstyle;

        app.findTextPreferences.findWhat = sel.contents;

        app.changeTextPreferences.appliedCharacterStyle = cstyle;

        app.changeTextPreferences.markupTag = tagName;

       

        var res1 = sel.findText();

       

        if(res1.length > 0)

        {

            for(var rCnt1 = 0; rCnt1 < res1.length; rCnt1++)

            {

               var cResult = res1[rCnt1];

               cResult.changeText();

                cResult.findText()[0].insertionPoints[0].associatedXMLElements[0].xmlAttributes.add('name','value');

            }

       }

     app.findTextPreferences = app.changeTextPreferences = null;