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

Export xml attribute values

Contributor ,
Mar 25, 2016 Mar 25, 2016

Copy link to clipboard

Copied

Dear java expert,

I was try to script export attribute value in the .txt format. I have attached screenshot for your reference.  Please suggestion me friends.

Screen Shot 2016-03-26 at 11.58.38 AM.png

I am using system: Mac, indesign Cs6.

Advance Thanks to all

TOPICS
Scripting

Views

777

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

correct answers 1 Correct answer

Contributor , Mar 28, 2016 Mar 28, 2016

Dear friends,

I have share my java coding in below, based on the above question.

var myDocument = app.activeDocument;

var log=new File(app.activeDocument.filePath+"/log.html");

log.encoding = "UTF-8";

log.open("w");

log.writeln("<html><body><table border=1>");

log.writeln("<tr><td>Text(In template)</td><td>Found(Href Tag)</td></tr>");

FindEmail(myDocument);

log.writeln("</table></body></html>");

log.close();

alert("process Completed");

function FindEmail(elm)

{

    for (var i = 0; i < elm.xmlElements.leng

...

Votes

Translate

Translate
Contributor ,
Mar 28, 2016 Mar 28, 2016

Copy link to clipboard

Copied

Dear friends,

Please tell any one suggestion in my above question?

Thanks,

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
Contributor ,
Mar 28, 2016 Mar 28, 2016

Copy link to clipboard

Copied

Dear java kings,

Please tell any one suggestion in my above question?

Advance Thanks to all,

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
Contributor ,
Mar 28, 2016 Mar 28, 2016

Copy link to clipboard

Copied

Dear friends,

I have share my java coding in below, based on the above question.

var myDocument = app.activeDocument;

var log=new File(app.activeDocument.filePath+"/log.html");

log.encoding = "UTF-8";

log.open("w");

log.writeln("<html><body><table border=1>");

log.writeln("<tr><td>Text(In template)</td><td>Found(Href Tag)</td></tr>");

FindEmail(myDocument);

log.writeln("</table></body></html>");

log.close();

alert("process Completed");

function FindEmail(elm)

{

    for (var i = 0; i < elm.xmlElements.length; i++)

    {

        XMLelementName=elm.xmlElements.markupTag.name.toString();

       if(XMLelementName=="img")

        {

             for(j=0; j<elm.xmlElements.xmlAttributes.length; j++) 

             {

                var cc =  elm.xmlElements.contents

                 //alert(cc);

                 var aa = elm.xmlElements.xmlAttributes.name

                  if(aa=="src")

                     {

                         //alert (aa);

                          var bb =  elm.xmlElements.xmlAttributes.value;

                         log.writeln("<tr><td>"+ cc +"</td><td>"+  elm.xmlElements.xmlAttributes.value +"</td></tr>");

                          //alert (cc  + "~~" + aa+ " ~~ "  + bb);

                      }

                 }

        }

        FindEmail(elm.xmlElements);

      

    }

       

}

Thanks,

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
People's Champ ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

Hi there is more interesting and performing imho:

var main = function(){

  var doc = app.properties.activeDocument,

  xmlFile = File ( Folder.temp+"/attr.xml" ),

  xmlObject,

  xmlAttrs, attrs = [], n = 0, i = 0,

  sep = "\t";

  if (!doc) return;

  doc.exportFile ( ExportFormat.XML, xmlFile );

  if ( !xmlFile.exists ) {

  alert("Unable to read xml data");

  return;

  }

  xmlFile.open('r');

  xmlObject = XML ( xmlFile.read() );

  xmlFile.close();

  xmlFile.remove();

  xmlAttrs = xmlObject.xpath("//*//@*");

  n = xmlAttrs.length();

  while ( i<n ) {

  attrs [ attrs.length ] = xmlAttrs.name()+sep+xmlAttrs;

  i++;

  }

  if ( !attrs.length ) {

  alert("Could'nt find any attributes.");

  return;

  }

  writeFile ( "Attribute Name"+sep+"Attribute Value"+"\r"+attrs.join("\r") );

};

var writeFile = function( data ) {

  var file = File ( Folder.desktop+"/attributes.csv" );

  file.open("w");

  file.write ( data );

  file.close();

  file.execute();

}

main();

FWIW,

Loic

Ozalto | Productivity Oriented - Loïc Aigon

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
Contributor ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

HI Loic.Aigon,

Thank you so match for your advance script. Very help full for me.

Just one question: Where is you are mention(add) the image tags for <img> in the script?

Example for my coding: if(XMLelementName=="img")

Please explain me friend.

Thanks

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
People's Champ ,
Mar 29, 2016 Mar 29, 2016

Copy link to clipboard

Copied

LATEST

just edit the xpath:

//img/@*


Loic

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