HI Loic, Any suggestions with my OP code, I tried again with some changes but still not fixed my issue. Could you please suggest what I am doing wrong? //removing unsed xml elements var mains = function() { var doc = app.properties.activeDocument, xes, xe; if (!doc) return; xes = doc.xmlElements[0].evaluateXPathExpression(".//*"); while ( xe = xes.pop() ) { xe.texts[0].isValid && !xe.texts[0].parentTextFrames.length && xe.remove(); } } var u; app.doScript("mains();",u,u,UndoModes.ENTIRE_SCRIPT); //main function var main = function() { myDoc=app.documents[0] corrs= { "Item #":"sku", "Description":"description", "Brand":"brand", "Product Dimensions":"product_dimensions", "Quantity":"quantity", "List Price":"list_price", "Pen Style":"pen_style", "Nib Type":"nib_type", "Nib Size":"nib_size", "Ink Color":"ink_color", "Color":"color" }; var sel = app.activeDocument.textFrames, tf, ps, ln, n = 0, tableHeader, lines,errors = [], check; for(z=0;z<sel.length;z++){ tf = sel ; var headers = {count:0}; var xe = tf.properties.associatedXMLElement; if ( !xe ) return; ps = xe.xmlContent; tableHeading = xe.evaluateXPathExpression ( "//table_heading" ); if ( !tableHeading.length ) return; ln = tableHeading[0].xmlContent.contents.split("\t"); n = ln.length; while ( n-- ) { headers[corrs[ln ]] = 0; headers.count+=1; } checkContents ( ps , headers ) ; } } function checkContents ( story , headers ) { var xes = story.associatedXMLElement.evaluateXPathExpression ( "//*[name(./..)='copy_frame']" ).reverse(), currIndex, currNumber, n = xes.length, i = 0, nXe, xEc, xEl, xeName, data = {}, lnCount = story.lines.length; var myarray=[]; var myarr=[]; for (k=0; k< story.lines.length; k++) { if ((story.lines .contents).search("Item #") != -1 ) { lnCount=lnCount-1-k; } else continue; } var line_contents=[], column_name=[]; var values=[]; var row=0; for (k=0; k< story.lines.length; k++) { if ((story.lines .contents).search("Item #") != -1 ) { line_contents=story.lines .contents; column_name = line_contents.split("\t"); for(row=k+1;row<=lnCount;row++){ if(story.lines[row].words[0].associatedXMLElements[0].markupTag.name == "table_subhead") {continue}; values=story.lines[row].contents.split("\t"); for(column=0;column<column_name.length;column++){ if (story.lines[row].words[column].associatedXMLElements[0].markupTag.name != corrs[column_name[column]]) { alert("InvalidTag"+story.lines[row].words[column].contents); } } } } } } var u; app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );
... View more