• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help need for Find and replace grep using in Xml tags!

Engaged ,
Sep 17, 2016 Sep 17, 2016

Copy link to clipboard

Copied

Hi Everyone,

I have a Textframe with value ($00.00) between two xml tags. one tag for "$" and another one for value(00.00).

Now I need find those value (00.00) and replace value(24.10). If I run the script, Its remove the price XML tag and updated the price.

My expectation is update theose value without removing the XML tag.

Please suggest me where I did the mistake in the code. Kindly find the screen shot and code for your reference.

     Before run the Script:                                                                                                              After Run the Script:

Screen Shot 2016-09-17 at 5.03.18 pm.png Screen Shot 2016-09-17 at 5.09.31 pm.png

Code:

var flgGREP="[$]\\d+[.]\\d+"

var Price="$24.10"

myLine=app.selection[0];

FindReplaceValue(flgGREP,Price,myLine);

function FindReplaceValue(findValue,replaceValue,Sapps){

    app.findGrepPreferences = app.changeGrepPreferences = null; 

    app.findGrepPreferences.findWhat = findValue; 

    app.changeGrepPreferences.changeTo = replaceValue;

    Sapps.changeGrep();

}

-yajiv

TOPICS
Scripting

Views

534

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Sep 17, 2016 Sep 17, 2016

That's because the XML tag (both opening and closing representations) is a special character but a generic one.

So the grep pattern above would fail because you have text like [TAG]$[TAG][TAG]00.00[TAG] will not be picked up by the grep engine.

However there is no (unless I am wrong) a metacharacter that would spot the tags marks. You can do it in text F/R but of course it's not as smooth than grep.

Bad news is that those special characters won't be saved if you do F/R on a tagged content (I mean i

...

Votes

Translate

Translate
Engaged ,
Sep 17, 2016 Sep 17, 2016

Copy link to clipboard

Copied

var flgGREP="(? <=$)\\d+\\.\\d+"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 17, 2016 Sep 17, 2016

Copy link to clipboard

Copied

Hi Skemicle,

Thank you for your prompt response.

The value is not updated to the text Frame.

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Sep 17, 2016 Sep 17, 2016

Copy link to clipboard

Copied

That's because the XML tag (both opening and closing representations) is a special character but a generic one.

So the grep pattern above would fail because you have text like [TAG]$[TAG][TAG]00.00[TAG] will not be picked up by the grep engine.

However there is no (unless I am wrong) a metacharacter that would spot the tags marks. You can do it in text F/R but of course it's not as smooth than grep.

Bad news is that those special characters won't be saved if you do F/R on a tagged content (I mean in the very case above).

Good luck for you is that you seem to knw the markupTag which host the price = copy_frame so I would do domething like :

var root = app.activeDocument.xmlElements[0];

var copy_frame_tags = root.evaluateXPathExpression (".//copy_frame" );

var tag;

while ( tag = copy_frame_tags.pop() ) {

     tag.contents=="00.00" && tag.contents="24.10";

}

HTH

Loic

Ozalto | Productivity Oriented - Loïc Aigon     

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 18, 2016 Sep 18, 2016

Copy link to clipboard

Copied

LATEST

Thank you Loic,

Its working like charm...

As well as I got Idea on evaluateXPathExpression works.

-yajiv

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines