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
Copy link to clipboard
Copied
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