fabianmoronzirfas
5/19/2015 - 5:57 AM

test.xml

var main = function() {
  // create yome xml and write it to file
  var root = new XML("<root/>");
  var child = new XML("<child/>");
  child.@string = "Hello Attribute"; // jshint ignore:line
  child.@num = 23; // jshint ignore:line
  root.appendChild(child);
  var file = new File("~/Desktop/test.xml");
  var xml = root.toXMLString();
  file.open("W");
  file.write(xml);
  file.close();

  // get the current doc
  var doc = app.activeDocument;
  // import the xml
  doc.importXML(file);
  // get the elements
  var xmlroot = doc.xmlElements[0];
  var xmlchild = xmlroot.xmlElements[0];
  // loop all attributes of element "child"
  // and write them into the console
  for (var i = 0; i < xmlchild.xmlAttributes.length; i++) {
    var attr = xmlchild.xmlAttributes[i];
    $.writeln(attr.name);
  }



};
main();
<root>
  <child string="Hello Attribute" num="23"/>
</root>