How to display the children under the parent of an xmll file using jquery ?
I want to display the children tags in a listview. In that listview i'm
adding the parent tag as a list-divider.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<page count="89" name="Sample">
<sections>
<section count="3" name="Alphabets" order="1">
<content file="220993.txt" order="1">A</content>
<content file="220994.txt" order="2">B</content>
<content file="220995.txt" order="3">C</content>
</section>
<section count="5" name="Numbers" order="2">
<content file="221006.txt" order="4">five</content>
<content file="221007.txt" order="5">four</content>
<content file="221008.txt" order="6">three</content>
<content file="221009.txt" order="7">two</content>
<content file="221010.txt" order="8">one</content>
</section>
<section count="2" name="Names" order="3">
<content file="221013.txt" order="9">Sam</content>
<content file="221014.txt" order="10">Sansha</content>
</section>
</sections>
</page>
Code:
$(xml).find('section').each(function () {
var section = $(this).attr("name");
var count = $(this).attr('count');
var order = $(this).attr('order');
$(this).children().each(function () {
var content = $(this).text();
var order = $(this).attr("order");
var seq = order + '' + $(this).attr('order');
$("#section_list").append('<li
data-role="list-divider">' + section + '</li>');
$("#section_list").append('<li><a href=""
class="style1" data-sequence="s' + seq + '" ><h2>'
+ content + ' </h2></a></li>');
$("#section_list").listview('refresh');
});
});
If i'm doing like this parent tag is repeating for every children.
Thanks in Advance.
No comments:
Post a Comment