我有一个看起来像这样的 XML 文件
<posts>
<post>
<username>MarchHare</username>
<date><day>4</day><month>May</month><year>2013</year></date>
<time><hour>18</hour><minute>0</minute><seconds>8</seconds></time>
<text>Have some wine.</text>
<post>
<username>Alice</username>
<date><day>4</day><month>May</month><year>2013</year></date>
<time><hour>18</hour><minute>0</minute><seconds>19</seconds></time>
<text>I don't see any wine.</text>
<post>
<username>MarchHare</username>
<date><day>4</day><month>May</month><year>2013</year></date>
<time><hour>18</hour><minute>0</minute><seconds>28</seconds></time>
<text>There isn't any.</text>
<post>
<username>Alice</username>
<date><day>4</day><month>May</month><year>2013</year></date>
<time><hour>18</hour><minute>0</minute><seconds>51</seconds></time>
<text>Then it wasn't very civil of you to offer it.</text>
<post>
<username>MarchHare</username>
<date><day>4</day><month>May</month><year>2013</year></date>
<time><hour>18</hour><minute>1</minute><seconds>23</seconds></time>
<text>It wasn't very civil of you to sit down without being invited.</text>
<post>
<username>Alice</username>
<date><day>4</day><month>May</month><year>2013</year></date>
<time><hour>18</hour><minute>2</minute><seconds>3</seconds></time>
<text>I didn't know it was /your/ table, it's laid for a great many more than three.</text>
</post>
</post>
</post>
</post>
</post>
</post>
</posts>
我正在尝试使用 jQuery 阅读。目前我正在使用这块js
target.append("<div class='postList'>");
$(data).find("post").each(function () {
$(target).append("<div class='postHeader'>");
$(".postHeader").append("<p class='user'>"+$(this).find("username").text()+"</p>");
$(".postHeader").append("<p class='date'>"+$(this).find("day").text()+"/"+$(this).find("month").text()+"/"+$(this).find("year").text()+"</p>");
$(".postHeader").append("<p class='time'>"+$(this).find("hour").text()+":"+$(this).find("minute").text()+":"+$(this).find("seconds").text()+"</p>");
$(".postHeader").append("</div>");
$(".postHeader").append("<div class='post'>");
$(".post").append("<p>"+$(this).find("text").text())+"</p>";
$(".post").append("</div>");
});
$(target).append("</div>");
这似乎不喜欢嵌套元素的想法并返回一个非常混乱的讨论。
关于如何很好地制作这个显示器的任何线索?(即没有混乱)
编辑:无法更改 XML。嵌套的存在是为了显示哪些帖子是回复,哪些不是