我有一个 xml,其中 xml 包含文件夹和图像详细信息。我使用 jquery 加载 xml,我得到了文件夹详细信息,但是现在我得到的图像路径不正确
图片/ftest1.png,images/fstest1.png,images/fsstest1.png,images/stest1.png,images/sstest1.png
如何得到所有?
我的代码
<script>
$(document).ready(function(){
$("#dvContent").append("<ul></ul>");
$.ajax({
type: "GET",
url: "books.xml",
dataType: "xml",
success: function(xml){
$(xml).find("FolderName").each(function(index, element){
var levels = $(this).parents("OrgFolderDetails").size();
var text = $(this).attr('name');
var text1 = $(this).text();
var html = "";
//alert($(this).find("child[value='"+text+"']"));
//alert($(this).children().size())
var level_child=$(this).children().size();
for(var j=0; j < level_child; j++){
alert($(this).children().attr('path'));
}
for(var j=0; j < levels; j++){
html += "-";
}
html += "<li> "+text+"</li>"; //add in that space after the dashes, and the <br>
$("#browser").append(html);
});
},
error: function() {
alert("An error occurred while processing XML file.");
}
});
});
xml
<?xml version="1.0" encoding="utf-8"?>
<OrgFolderDetails>
<FolderName name="Main Folder"></FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName name="First Sub Folder">
<source path="images/ftest1.png"></source>
<source path="images/ftest2.png"></source>
<source path="images/ftest3.png"></source>
<source path="images/ftest4.png"></source>
<source path="images/ftest5.png"></source>
</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName name="First Sub Siub Sub Folder">
<source path="images/fstest1.png"></source>
<source path="images/fstest2.png"></source>
<source path="images/fstest3.png"></source>
<source path="images/fstest4.png"></source>
<source path="images/fstest5.png"></source>
</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName name="First Sub Siub Sub Folder">
<source path="images/fsstest1.png"></source>
<source path="images/fsstest2.png"></source>
<source path="images/fsstest3.png"></source>
<source path="images/fsstest4.png"></source>
<source path="images/fsstest5.png"></source>
</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName name="First Sub Sub Sub Sub Folder"></FolderName>
<TheChildren/>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
<OrgFolderDetails>
<FolderName name="Second Sub Folder">
<source path="images/stest1.png"></source>
<source path="images/stest2.png"></source>
<source path="images/stest3.png"></source>
<source path="images/stest4.png"></source>
<source path="images/stest5.png"></source>
</FolderName>
<TheChildren>
<OrgFolderDetails>
<FolderName name="Second Sub Sub Folder">
<source path="images/sstest1.png"></source>
<source path="images/sstest2.png"></source>
<source path="images/sstest3.png"></source>
<source path="images/sstest4.png"></source>
<source path="images/sstest5.png"></source>
</FolderName>
<TheChildren/>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
</TheChildren>
</OrgFolderDetails>
提前致谢