javascript - strip content of a table -


i have static table lots of data in it. want strip out data javascript , crate xml result result.

table sample:

    <table width="500" border="0" cellspacing="0" cellpadding="0">     <tr>     <td width="50">sn</td>     <td width="200">item</td>     <td width="500">discription</td></tr>   <tr>     <td>1</td>     <td width="200">item 1</td>     <td>this lenghty item discription</td>   </tr> 

expected xml result created:

<content> <sn>1</sn> <item>item1</item> <discription>this lenghty item discription</discription> </content> 

...

can please provide me simple js code use. thanks

    <table width="500" border="0" cellspacing="0" cellpadding="0">     <tr>     <td width="50">sn</td>     <td width="200">item</td>     <td width="500">discription</td></tr>   <tr>     <td>1</td>     <td width="200">item 1</td>     <td>this lenghty item discription</td>   </tr> 

solution...

var content = []; $("table tr").each(function(){    var self = this;    content.push({        'content': {           'sn': $(self).find('td:first-child').text(),           'item': $(self).find('td:nth-child(2)').text(),           'description: $(self).find('td:nth-child(3)').text()        }    }) });  var xml = x2js.json2xml_str(content);  

the above solution uses x2js library.

expected xml result created:  <content> <sn>1</sn> <item>item1</item> <discription>this lenghty item discription</discription> </content> 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -