본문 바로가기
JavaScript

Fetch (2) - xml 데이터 읽기

by 우영11 2023. 6. 26.

DOMParser() 객체를 이용하고

parseFromString()함수를 이용해 처리한다.

fetch("responseXML.xml")
    .then(function(response){
        return response.text();
    })
    .then(function(data){
        let parser=new DOMParser();
        let xmlData=parser.parseFromString(data, "application/xml");

	// xmlData로 받은 데이터를 사용
        let studentList=xmlData.querySelectorAll("student");
    })