IT
[jQuery] jQuery를 이용한 xml 파싱
정미나
2010. 7. 2. 14:41
* xml 파일
* 소스 파일
<?xml version="1.0" encoding="utf-8" ?>
- <root>
- <item>
<no>번호</no>
<title>제목</title>
<type>타입</type>
</item>
</root>
- <root>
- <item>
<no>번호</no>
<title>제목</title>
<type>타입</type>
</item>
</root>
* 소스 파일
$.ajax({
type: "get"
,dataType: "xml"
,url: "xml파일 주소"
,success: function(xml){
if($(xml).find("item").length > 0){ // null check
$(xml).find("item").each(function(){ // item 수만큼 loop
// item 요소 중 title 읽어오기.
var title = $(this).find("title").text();
});
}
}
,error: function(){ alert("xml error!!"); }
});
,dataType: "xml"
,url: "xml파일 주소"
,success: function(xml){
if($(xml).find("item").length > 0){ // null check
$(xml).find("item").each(function(){ // item 수만큼 loop
// item 요소 중 title 읽어오기.
var title = $(this).find("title").text();
});
}
}
,error: function(){ alert("xml error!!"); }
});