how to retrieve xml attribute value .....

11 views
Skip to first unread message

sachin Chaudhary

unread,
Mar 14, 2013, 6:08:08 AM3/14/13
to jsl...@googlegroups.com
Hi all,

   Please provide me solution how to parse xml using spidermonkey  or jslibs . i tried small program but stuck at attribute value.....

/*************    test.xml ************/

<note>
<to key='hello'>joseph</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>


/***********   parse.js ***********/


var loadModule = host.loadModule;
loadModule('jsstd');
loadModule('jsio');
var buf;
var file = new File('../jslibs/test.xml');
   if ( file.exist ) {
    
file.open( File.RDONLY );
    buf = file.read(65535);
print(buf);
file.close();
}
var data = stringify(buf);
var xmlData = new XML(data);
print('\nattribute :'+xmlData.to+'\n');


this program prints xml file and prints value within tags ( <to></to>  ) but i am unable to retrieve value of attribute  ( key="hello" attribute  of tag <to> )

how will i be able to do this...


regards

sachin  




Reply all
Reply to author
Forward
0 new messages