I’m new to XML. When I try put in some “cases” into it’s XML-parent (called ITEM), it fills into all the ITEMS, and dublicates on some. I have 6 cases, but somehow it shows 12 in one of the ITEMs.
I have an XML-file that looks like this:
<menu>
<item>
<headline />
<body />
<cases>
<case><link /></case>
<case><link /></case>
<case><link /></case>
<case><link /></case>
<case><link /></case>
<case><link /></case>
<case><link /></case>
</cases>
</item>
<item>
<headline />
<body />
</item>
On the ITEM that hasn’t any cases in it, I don’t want any cases to be shown. I only want the cases to be “put into” the right ITEM.
How do I do this?
To display the items, I use:
$(xml).find('item').each(function(){
var headline = $("headline", this).text();
$("ul").append("<li class='" + name + "'><h3>" + headline + "</h3>");
if ($(xml).find('case').length != 0) {
//I want it to place this, in the correct ITEM, and not in all items.
$("ul li").append("<ul class='cases'>");
$(xml).find('case').each(function(){
caseLink = $("link", this).text();
$("ul li .cases").append("<li><a href='" + caseLink + "' /></a></li>");
});
$("ul li").append("</ul>");
}
$("ul").append("</li>");
});
What am I doing wrong???
Thank you in advance…
The problem was, that I called the (XML) twice.
The second (and the following) time the “if (XML)” is called, use “(this)” instead.
Change:
To:
That did it for me.