html - jQuery to Retrieve Data From an XML File -


i need retrieve attribute value in below xml :

<datasource id="social_messages2" serial="20140205152417255" type="feed" subtype="" mtime="2014-02-05t14:24:17.2554296z" mtime_unix="1391610257" tz="+0100" ttl="5"> <entry id="13036083562208554600000000" ctime="2014-02-05t14:19:17.5991796z" mtime="2014-02-05t14:19:17.5991796z" ctime_unix="1391609958" mtime_unix="1391609958"> <field name="design">user</field> <field name="message">rt @thatssarcasm: summer 2014 yet</field> <field name="nickname">@devine_318</field> <field name="mid">543606</field> <field name="iconname"/> <field name="timestamp">2014-01-30 15:17:46</field> <field name="viz_image"/> <field name="via">twitter</field> <field name="date">2014-01-30</field> <field name="time">15:17:46</field> </entry>  

for example need retrieve time (15:17:46) how can write below code not working in way code work if tags (<time>15:17:46</time>) how can retrieve value of field see below code :

function parsexml(xml) {     $(xml).find('entry').each(function() {         console.log(this);         var $show = $(this);         var via = $show.find('via').text();         var message = $show.find('message').text();         var time = $show.find('time').text();         var html = '<tr><td class="bold"><img src="'+ via +'"/></td><td class="hide">' + time + '</td><td class="bold">' + message + '</td></tr>';         $('#show_table').append($(html));     }); } 

you need select based on attribute value instead of tag name. substitute

$show.find('time').text() 

with

$show.find("field[name='time']").text() 

when supply text no preceeding character. ie "text" selector. jquery selects elements tag name. prefixing . jquery search elements class named text. eg. ".foo" searches elements foo class. search attribute value need tell jquery attributes search , optionally. search element attribute name name , value time need use attribute selector. [attributename='valuetofilteron'] in case [name='time']


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -