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

loop through each xml element in xml file using extendscript toolkit cs6

Guest
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

hii all

I have an xml like:

<root>

<seq path="chapter02/ch02_reader_0.html"/>

  <seq path="chapter02/ch02_reader_1.html"/>

  <seq path="chapter02/ch02_reader_2.html"/>

  <seq path="chapter02/ch02_reader_3.html"/>

</root>

How can i read the value of the path attribute in extendscript?

I am able to read the file using File.read()

But how do i get the path attribute values?

Please suggest

Thanks

TOPICS
Scripting

Views

694

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 ,
Sep 10, 2016 Sep 10, 2016

Copy link to clipboard

Copied

LATEST

Hi,

Try this.

You got the all attributes value in the text file.

//*******************************

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();

//*******************************

Thanks

KS

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