How to parse XML data inside column in javascript? -


i have xml data in format:

<data> <item type='string'>abc</item> <item type='date'> <year>2015</year> <month>may</month> <day>24</day> </item> </data> 

i parsing in format:

var obj = somevariable.record[0].column[0].gettext(); //obj 

how can parse date 2015/may/24?

in pure javascript can follows:

var xmlv = document.getelementsbytagname("data")[0]; var date = xmlv.queryselector('item[type="date"]'); var year = date.queryselector('year').innerhtml; var month = date.queryselector('month').innerhtml; var day = date.queryselector('day').innerhtml;  var parseddate = year + '/' + month + '/' + day; 

note uses queryselector function not work in older browsers fine in ie8+.

pure js version (as above) https://jsfiddle.net/n0xamj6l/

jquery version (neater , more compatible) https://jsfiddle.net/t4pr8oyu/


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -