How to get attribute name and its values from xml using javascript?


hi,

 

i trying attribute name , values xml(i have saved xml in folder) using javascript.the code has given below,

 

var currentfolder = folder.selectdialog();

    if (currentfolder == null) exit();

    var currentfolderpath = currentfolder.absoluteuri + "/";

    var xmlfile = new file(currentfolderpath +xmlname);  

    if (!xmlfile.exists) exit();  

  xmlfile.open("r");

  var xmlstr = xmlfile.read();

  xmlfile.close();

var root = new xml(xmlstr);

  var linksarr = [];

 

   var componentlist = root.xpath("//product_family"); 

   var componentslength = componentlist.length();  var component; 

   var product;var pricevalue;var products;var itemvalue; 

   (var c = 0; c <componentslength; c++)

   {

    component = componentlist[c];    

    product=component.xpath("//products").children()[c];

    for(var d=0;d<product.length();d++)

    {

        prod=product.children().length();

        for(var x=0;x<product.children().length();x++)

        {

            attribute=product.children()[x];  

            }

    }

}

 

in this,attribute=product.children()[x] displays values available in product table..first displays attribute names , values..it reads line line..but need display each attribute name , values. after displaying first attribute , values want go next attribute name.please me complete script.

 

thanks in advance,

vimala l

see following example know how attribute values using javascript.

 

var myxml = new xml("<root><p att1=\"value1\" att2=\"value2\"></p></root>"); var myxmlelement = myxml.xpath ("//p"); alert(myxmlelement.attributes()[0].name()+": "+myxmlelement.attributes()[0].tostring()); 

 

~green4ever



More discussions in InDesign Scripting


adobe

Comments

Popular posts from this blog

Thread: Can not create raid array: mdadm: no raid-devices specified.

Thread: HOW TO: Package and theme GTK+ / Gtkmm apps in Linux for Windows

Thread: Twinview issues