저는 Adobe RoboHelp (도움말 문서 용)에서 생성 된 일부 XML을 반복 할 수있는 기본 코드를 가지고 있습니다. 이것은 잘 작동하지만, 주제가 작성자가 원하는만큼 중첩 될 수 있기 때문에, 나는 단지 .each()
루프를 중첩하는 것이 아니라이 XML을 반복하는 좋은 방법이 필요하다.jQuery로 XML 반복하기
다음은 XML이
<?xml version="1.0" encoding="utf-8"?>
<!--RoboML: Table of Content-->
<roboml_toc>
<page title="Welcome" url="Welcome.htm"/>
<book title="Getting Started" url="Getting_Started/Initial_Setup.htm">
<page title="Initial Setup" url="Getting_Started/Initial_Setup.htm"/>
<page title="Customize Settings" url="Getting_Started/Settings.htm"/>
</book>
<book title="Administrator Services" url="Administrator_Services/General_Administrator.htm">
<book title="Portal Workspace" url="Administrator_Services/Portal_Workspace/AdminHome.htm">
<page title="Home" url="Administrator_Services/Portal_Workspace/AdminHome.htm"/>
<page title="Portal Accounts" url="Administrator_Services/Portal_Workspace/Portal_Accounts.htm"/>
</book>
<book title="SpamLab" url="Administrator_Services/SpamLab/SpamLab_Admin_General.htm">
<page title="Alerts" url="Administrator_Services/SpamLab/Alerts.htm"/>
<page title="Spam Quarantine" url="Administrator_Services/SpamLab/Admin_Spam_Quarantine_.htm"/>
</book>
</book>
<book title="User Services" url="User_Services/General_User.htm">
<book title="Portal Workspace" url="User_Services/Portal_Workspace/Home.htm">
<page title="Home" url="User_Services/Portal_Workspace/Home.htm"/>
<page title="Self Help" url="User_Services/Portal_Workspace/Self_Help.htm"/>
</book>
<book title="SpamLab" url="User_Services/SpamLab/SpamLab_General.htm">
<page title="Spam Quarantine" url="User_Services/SpamLab/Spam_Quarantine.htm"/>
<page title="Virus Quarantine" url="User_Services/SpamLab/Virus_Quarantine.htm"/>
</book>
<book title="Encryption" url="User_Services/Encryption/Encryption_General.htm">
<page title="Outlook Plug-in" url="User_Services/Encryption/Encryption_Outlook_Plug_in.htm"/>
</book>
</book>
</roboml_toc>
<page>
같은 기사를 외모, 그리고 <book>
폴더 무엇이다.
그녀는 태그의 한 단계 깊은 볼 수 있습니다 내 jQuery 코드,의
//Get the TOC
$tocOutput="";
$.get(tocURL,function(toc){
$(toc).children().each(function(){
$tocOutput+="<li><a href='"+$(this).attr("url")+"'>"+$(this).attr("title")+"</a>";
if(this.tagName=="BOOK"){
$tocOutput+="<ul>";
$(this).find("page").each(function(){
$tocOutput+="<li><a href='"+$(this).attr("url")+"'>"+$(this).attr("title")+"</a></li>";
});
$tocOutput+="</ul>";
}
$tocOutput+="</li>";
});
$("#list").html($tocOutput);
내가 더 좋은 방법은 그냥 루프는 모든 요소를 통해 거기 알고 요소가 어린이 등하지만이있는 경우 다음 결정 그것을하는 방법을 생각할 수 없다.
도움을 주시면 대단히 감사하겠습니다.
그냥 궁금 해서요. 왜 클라이언트에서이 작업을 수행해야합니까? XSLT 변환을 서버에 적용하고 HTML을 보내지 않는 이유는 무엇입니까? xml은 동적입니까? 변환 된 html을 서버에 캐시 할 수 없습니까? –
상관없이 해결책을 찾았 기 때문에 기쁘다 - 지금 키스 동의를 받아 들인다. –
나는 환멸을 느낀다! 이것은 단지 개념의 증거였습니다 .... 실제로 저는 사람들에게 깊은 감명을주고 싶었습니다. 그들은 나를 칭찬과 함께 샤워하고 있으므로 가치가 있습니다. 결국 우리는이 서버 측을 수행 할 것이라고 생각합니다. –