Home Forums General XMetaL Discussion Makro Search Entity and Replace it Reply To: Makro Search Entity and Replace it

Derek Read

Reply to: Makro Search Entity and Replace it

There is no API dedicated to this type of thing, but I think you can probably do what you want with a combination of other APIs.

With the following document open in XMetaL Author (Enterprise or Essential)…
[code=Journalist demo document]
 
 
 
]>

  <?xm-replace_text {Article Title}?>
 
a&old;b&somethingelse;c&old;d a&somethingelse;b&test;c&somethingelse;d 
December 19, 2013 2:21:52 PM

[/code]

…running the following script will replace all the “old” entity references with references to the “new” entity.
[code=sample script]//XMetaL Script Language JScript:
if((ActiveDocument.ViewType == sqViewNormal)||(ActiveDocument.ViewType == sqViewTagsOn)) {
var entRefToReplace = “old”;
var entRefToInsert = “new”; //this entity ref must be declared
var rng1 = ActiveDocument.Range;
rng1.MoveToDocumentStart();
var rng2 = rng1.Duplicate;
rng1.GotoNext(0);
while(rng2.IsLessThan(rng1)) {
if(rng2.ContainerName == “.ENTREF”) {
if(rng2.ContainerNode.nodeName == entRefToReplace) {
Application.Alert(“found one: ” + rng2.ContainerNode.nodeName);
rng2.SelectElement();
rng2.Delete();
rng2.InsertEntity(entRefToInsert);
}
}
rng2.GotoNext(0);
rng1.GotoNext(0);
}
}[/code]

Reply

Products
Downloads
Support