Skip to main content
tpk1982
Legend
September 9, 2016
Answered

Place a 'dot' inside of xml tags

  • September 9, 2016
  • 1 reply
  • 863 views

Hi,

I need to insert a dot if a column is as empty. But when i use find and replace method it removes tag in between the tabs. Is it possible to place a dot without affecting the xml tags?

app.findGrepPreferences = null;     app.changeGrepPreferences = null; 

app.findGrepPreferences.findWhat="\\t\\t";

app.changeGrepPreferences.changeTo= "\\t.\\t";

app.changeGrep();

Thanks,

K

This topic has been closed for replies.
Correct answer Loic.Aigon

Need to add dot only in the empty tagged content in the selected area? But may i know why the previous words get deleted?


var main = function() { 

 

  var doc = app.properties.activeDocument,  

  found, n, xe; 

 

  if ( !doc || app.selection.length!=1 || !app.selection[0].properties.parentStory ) return; 

 

  sel = app.selection[0];

  (sel instanceof TextFrame) && sel = sel.parentStory;

  var xes = sel.associatedXMLElements;

  n = xes.length;

 

  while ( n-- ) { 

  xe = xes;

  xe.contents=="" && xe.contents=".";

  } 

 

 

main();

1 reply

Loic.Aigon
Legend
September 9, 2016

Is it possible to place a dot without affecting the xml tags?

Not through F/R. You may need to reach the xmlElement and set contents. I would preferably target the xmlElement specifically through EvaluateXPathExpression but here is an approach.

var main = function() {

  var doc = app.properties.activeDocument,

  found, n, xe;

  if ( !doc ) return;

  app.findTextPreferences = app.changeTextPreferences = null;

  app.findTextPreferences.findWhat = "^t<FEFF><FEFF>^t"

  found = doc.findText();

  n = found.length;

  while ( n-- ) {

  xe = found.associatedXMLElements[1];

  xe.contents = ".";

  }

}

main();

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon

tpk1982
tpk1982Author
Legend
September 9, 2016

Thanks Loic, but when i run the provide code, it shows "Undefined is not an Object" in line 15

Loic.Aigon
Legend
September 9, 2016

I see. As <FEFF> is a kind of generic metacharacter, it may imply some other found result is not related to a XMLElement.

Let's make this safer:

var main = function() {

  var doc = app.properties.activeDocument,

  found, n, xe;

  if ( !doc ) return;

  app.findTextPreferences = app.changeTextPreferences = null;

  app.findTextPreferences.findWhat = "^t<FEFF><FEFF>^t"

  found = doc.findText();

  n = found.length;

  while ( n-- ) {

  xe = found.associatedXMLElements;

  if ( xe.length ) {

  xe = xe [ xe.length-1 ];

  xe.contents = ".";

  }

  }

}

main();