Skip to main content
tpk1982
Legend
November 8, 2017
Answered

XML Tage name

  • November 8, 2017
  • 2 replies
  • 2369 views

Hi,

I have three line table coded with XML. I need to check  row 2 and 3 XML tag name match with row 1 XML tag name.   

Entire Line 1 is coded by a single line XML tag name. Though we can take name from row 2 for now. I have a huge list for every header name relevant XML tag name.

I tried to get every tag name separated by tab. But it throws wrong tag name. Please suggest. Thanks.

var para=app.selection[0];

var lines=para.contents.split('\r');

var no_of_lines = lines.length;

for(line = 0; line < no_of_lines; line++)

{

var x = lines[line].split('\t');

var mySelWords = x.length;

for(i=0;i<x.length;i++){

        alert(x+" ------> "+para.lines[line].words.associatedXMLElements[0].markupTag.name)

    }

}

I have attached the sample file.

Test.zip - Box

Thanks,

K

Message was edited by: kk kk

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi Jongware,

Thanks for your reply. Yes I aware the count of each word length between the tab separated is diffeerent. I thought in between the tab the word is coding by only one tag. So even it have two or three words, the first and second word contain same tag.

Thanks,

K


var main = function() {

var sel = app.properties.selection, tf, ps, ln, headers = {count:0}, n = 0, tableHeader, lines,errors = [], check;

if ( !sel || sel.length!=1 || !(sel[0] instanceof TextFrame) ) return;

tf = sel[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[ln] = 1;

headers.count+=1;

}

lines = ps.lines;

n = lines.length;

while ( n-- ) {

if ( n==0 ) break;

ln = lines;

check = checkLine ( ln, headers );

if ( check.length ) {

errors.push ( "Line:"+(n+1)+":\r\t"+check.join("\r\t-") );

}

}

alert(errors.length? errors.join("\r") : "Seems fine");

}

function checkLine ( line, headers ) {

var xes = line.associatedXMLElements, n = xes.length, lineTagCount = 0, nXe, missing = [], xeName;

while ( n-- ) {

nXe = xes;

xeName = nXe.markupTag.name;

if ( xeName=="copy_frame" ) continue;

if ( headers[xeName] ) {

lineTagCount+=1;

}

else {

missing.push ( xeName );

}

}

return missing;

}

var u;

app.doScript ( "main()",u,u,UndoModes.ENTIRE_SCRIPT, "The Script" );

2 replies

Loic.Aigon
Legend
November 9, 2017

I can imagine but the second approach is more generic hence the lack of details. I won't have time to pursue this but you have the main idea now

on a plus note, it seems the data was generated from some kind of data management tool. The table structure can be saw in the data. In that case, you could have tried to turn those tables into indesign own xml syntax for tables. You will have a quick way then to ensure everything is on teh right spot and use cell/table styles for data representation.

tpk1982
tpk1982Author
Legend
November 9, 2017

Hi Loic,

Thanks for pointing me with the table structure in the data management tool. Yes the operator pulling data from external plugin.

Sorry I ate most of you time today. But it is a learning experience for me because this is the first project I am working with XML.

Besides this, I have more work with this script like excluding subheading if anything come in between the row.. some text frames contains paragraph and then it follow with table.. like that..

Anyhow a big THANKS again for your contribution with this thread..

I am really happy with the solution found here.

Thanks,

K

tpk1982
tpk1982Author
Legend
November 9, 2017

Hi,

Could you please anyone suggest if you know anything related to my question? It is very helpful to finish my script.

Thanks,

K

Jongware
Community Expert
Community Expert
November 9, 2017

You assume no difference between the tab separated line ('x') and the 'words' in that same line 'para.lines[line].words[..]'. They are clearly not the same; several of your tab contents contain more than a single word.

tpk1982
tpk1982Author
Legend
November 9, 2017

Hi Jongware,

Thanks for your reply. Yes I aware the count of each word length between the tab separated is diffeerent. I thought in between the tab the word is coding by only one tag. So even it have two or three words, the first and second word contain same tag.

Thanks,

K