0

私はこのような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 は変更できません。どの投稿が返信で、どの投稿が返信でないかを示すためのネストが存在します

4

1 に答える 1