1. 컨트롤러에서 json으로 변환 후 javascript로 html 구현
<server>
URL url = new URL("http://www.ut.ac.kr/xmlout/Area.xml"); InputStream is = url.openStream(); String str = ""; StringBuilder sb = new StringBuilder();BufferedReader br = new BufferedReader(new InputStreamReader(is,"utf-8")); try {
while ((str = br.readLine())!= null) {
sb.append(str); }
} catch (Exception e) {
e.printStackTrace(); } finally {
if (is != null) {
is.close(); br.close(); }
}
JSONObject xmlJSONObj = XML.toJSONObject(sb.toString());
<client>
<script>
var json
function getDoc() {
json = JSON.parse('${xml}'); var items = json.Info.items; items.forEach(function (row) { var cat = row.Category; var name = row.Name; var tel = row.Tel; var lati = row.Latitude; var longti = row.Longitude;
});}
</script>
2.jstl로 파싱
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<x:parse var="out" xml="${xmlData}"/>
<x:forEach select="$out/Info/items" var="item">
<li class="map" title="<x:out select="Name"/>" lat="<x:out select="Latitude"/>" lng="<x:out select="Longitude"/>">
[<x:out select="Category"/> ] 상호 : <x:out select="Name"/></li>
</x:forEach>