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

Highlight the Modified content in the InDesign Document

Participant ,
Dec 26, 2021 Dec 26, 2021

Copy link to clipboard

Copied

Hi Professional,

I have gotten the modified content based on the XML and the InDesign Document. And on the modified content I have highlighted the content. But in that, I have facing an issue, the content shows highlighted when there is any special character(like bullet-in, quotation, tilde, and soon) in the document. For this, I have attached the script which I used to get the modified content having the highlight option.

 

var allCDATA = [];
myXMl = app.activeDocument.xmlElements[0];
var myXmlNode = myXMl.evaluateXPathExpression("//tradingbell_root");
var myFrame = app.activeDocument.textFrames;
for (var i = 0; i<myFrame.length; i++) {
var mySelectedXMLItem = myFrame[i].associatedXMLElement;
if(mySelectedXMLItem != null && mySelectedXMLItem.markupTag.name != null)
{
var node_TBGUID = myFrame[i].associatedXMLElement.xmlAttributes.itemByName("TBGUID").value;
var myFrames = myFrame[i].texts[0].contents;
var xmlTree = GetXMLFile();
var content = new XML(xmlTree);
var myDoc = app.activeDocument;
myLinks = myDoc.links;
for (j = myLinks.length - 1; j >= 0; j--)
{
myName = myLinks[j].filePath;
var ext = myName.substring(myName.length-3,myName.length) ;
if (ext=="xml")
{
var myXMLFile = File(myName);
var myResult = myXMLFile.open("r", undefined, undefined);
if(myResult == true){
var myXMLDefaults = myXMLFile.read();
myXMLFile.close();

} // if(myResult)
} // if(ext)
} // for
var elements =getAllAttributeValues ("TBGUID");
for(var k = 0;k<elements.length;k++)
{
if(elements[k] == node_TBGUID)
{
var getxmlcontent = getCDATAWithID(myXMLFile, "TBGUID", elements[k]);

var testL=myFrames;
var testR=getxmlcontent;
if(testR !=testL)
{
alert("Modified Content: " +mySelectedXMLItem.markupTag.name+"_" + getxmlcontent)
app.findGrepPreferences = NothingEnum.NOTHING;
var searchText = testL;
app.findGrepPreferences.findWhat = searchText ;
var list = app.activeDocument.findGrep ();
try
{
var new_Style = app.documents[0].characterStyles.item("underlie_Text");
new_Style.name;
}
catch (myError){
var new_Style = app.documents[0].characterStyles.add()
new_Style.name = "underlie_Text";
}
new_Style.underline= true;
new_Style.underlineColor = "C=0 M=0 Y=100 K=0";
new_Style.underlineType = "Solid";
new_Style.underlineWeight = "12 pt";
new_Style.underlineOffset = "-3 pt";
for(var i = 0; i < list.length; i++)
{
list[i].appliedCharacterStyle = "underlie_Text";
}
alert("Process Completed");
}
if(testR == testL)
{
alert("Content are same")
}
}
}
}
} // first for loop

function GetXMLFile()
{
myDoc = app.activeDocument;
myLinks = myDoc.links;
for (j = myLinks.length - 1; j >= 0; j--)
{
myName = myLinks[j].filePath;
var ext = myName.substring(myName.length-3,myName.length) ;
if (ext=="xml")
{
var myXMLFile = File(myName);
var myResult = myXMLFile.open("r", undefined, undefined);
if(myResult == true)
{
var myXMLDefaults = myXMLFile.read();
myXMLFile.close();
var myXMLDefaults = new XML(myXMLDefaults);
return myXMLDefaults;
}
}//for
}

}
function getAllAttributeValues(attributeName){
var allAttributes = [];
var allNodes = content[0].xpath("//*[@"+attributeName+"]");
for(var i = 0; i < allNodes.length(); i++){
allAttributes.push(allNodes[i].attribute(attributeName).toString());
}
if(allAttributes.length > 0){
return allAttributes;

}
else{
return null;
}
}

function getChildData(nodeData){
for(var c = 0; c < nodeData.children().length(); c++){
if(nodeData.children()[c].toXMLString().toString().indexOf("<![CDATA[") == 0){
allCDATA.push(nodeData.children()[c].toString());
}
if(nodeData.children()[c].children().length() > 0){
getChildData(nodeData.children()[c]);
}
}
}
function getCDATAWithID(inputXML, attribute, id){
var CDATA = [];
if(inputXML.exists == true) {
inputXML.open('r');
var text = inputXML.read();
inputXML.close();
var content = new XML(text);
var elements = content.xpath("//CDATA");
for(var n = 0; n < elements.length(); n++){
if(elements[n].parent()["@"+attribute].toString() == id){
CDATA.push(elements[n].toString());
}
}
}
return CDATA;
}

-Monisha
TOPICS
How to , Scripting

Views

94

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
Participant ,
Dec 27, 2021 Dec 27, 2021

Copy link to clipboard

Copied

LATEST

MonishaRajendran_0-1640672125471.png

Here I have attached the screenshot where I have facing the special character replacement issue in the XML file but not in the InDesign Document. 

-Monisha

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