EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     Help me create a Macro
Register To Post

Threaded | Newest First Previous Topic | Next Topic | Bottom
Poster Thread
prashob12
Posted on: 5/12/2008 12:03 pm
Just popping in
Joined: 4/28/2008
From:
Posts: 15
Help me create a Macro
Hello:

Please help me to create a macro:

I want to delete the follwoing:

<absatz>(<[^>]+>){1,20}</absatz> (empty elements)

but there is a condition i want to delete the above only when it comes in the following parent element i.e..
<rubrum>
....
</rubrum>

For e.g.
<rubrum>
<absatz><hervor typ="f"><?font Start ?>BUNDESARBEITSGERICHT</hervor></absatz>
<absatz><hervor typ="f"></hervor></absatz>
<absatz><hervor typ="f">URTEIL<?font Ende ?></hervor>
</rubrum>

The above should apply to all the XML files in a particular path.

Thanks in Advance
prashob12
Posted on: 5/12/2008 3:12 pm
Just popping in
Joined: 4/28/2008
From:
Posts: 15
Re: Help me create a Macro
Please Reply someone can solve this problem & help me out
Yutaka
Posted on: 5/12/2008 9:05 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2424
Re: Help me create a Macro
Quote:

prashob12 wrote:
Hello:

Please help me to create a macro:

I want to delete the follwoing:

<absatz>(<[^>]+>){1,20}</absatz> (empty elements)

but there is a condition i want to delete the above only when it comes in the following parent element i.e..
<rubrum>
....
</rubrum>

For e.g.
<rubrum>
<absatz><hervor typ="f"><?font Start ?>BUNDESARBEITSGERICHT</hervor></absatz>
<absatz><hervor typ="f"></hervor></absatz>
<absatz><hervor typ="f">URTEIL<?font Ende ?></hervor>
</rubrum>

The above should apply to all the XML files in a particular path.

Thanks in Advance


Go to Customize > Search tab, and check "Regular Expressions Can Match New Line Characters", and set "Additional Lines to Search for Regular Expressions" to 10.

Find:
<rubrum>(.*?)<absatz>(<[^>]+>){1,20}</absatz>(.*?)</rubrum>

Replace with:
<rubrum>\1\3</rubrum>


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

prashob12
Posted on: 5/13/2008 1:00 pm
Just popping in
Joined: 4/28/2008
From:
Posts: 15
Re: Help me create a Macro
Thanks a lot for replying

I tried what u told, but the number of Empty elements present in the <rubrum> is many, so if i use the replacment option it deletes one instance at a time, and the number of files with such instances are also many, so it will be time consuming.

I created a macro to replace all empty elements in <rubrum> at one go:

document.selection.Find("<rubrum>",eeFindNext | eeFindReplaceRegExp);
document.selection.CharLeft(false,1);
editor.ExecuteCommandByID(4153);
document.selection.Find("</rubrum>",eeFindNext | eeFindReplaceRegExp);
document.selection.Replace("<absatz>(<[^>]+>){1,20}</absatz>","",eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("<absatz></absatz>","",eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
document.selection.CharRight(false,1);

But i dont know how to make it run on all the files.
There are 1000's of such files.

Thanks in Advance!!
Yutaka
Posted on: 5/13/2008 9:59 pm
Webmaster
Joined: 9/28/2006
From: Redmond
Posts: 2424
Re: Help me create a Macro
Quote:

prashob12 wrote:
Thanks a lot for replying

I tried what u told, but the number of Empty elements present in the <rubrum> is many, so if i use the replacment option it deletes one instance at a time, and the number of files with such instances are also many, so it will be time consuming.

I created a macro to replace all empty elements in <rubrum> at one go:

document.selection.Find("<rubrum>",eeFindNext | eeFindReplaceRegExp);
document.selection.CharLeft(false,1);
editor.ExecuteCommandByID(4153);
document.selection.Find("</rubrum>",eeFindNext | eeFindReplaceRegExp);
document.selection.Replace("<absatz>(<[^>]+>){1,20}</absatz>","",eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
document.selection.Replace("<absatz></absatz>","",eeFindNext | eeReplaceSelOnly | eeReplaceAll | eeFindReplaceRegExp);
document.selection.CharRight(false,1);

But i dont know how to make it run on all the files.
There are 1000's of such files.

Thanks in Advance!!


If you have so many files, how about ReplaceInFiles Method (Editor object)?


----------------
Yutaka Emura
Developer of EmEditor
http://www.emeditor.com/

Threaded | Newest First Previous Topic | Next Topic | Top


Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文