2013-05-05 2 views
0
  1. 특정 값의 구문 분석 및 검색을 위해 xml 인 서블릿에서 xmlDoc으로 응답을 변환해야합니까?
  2. 그렇다면 다음 코드가 맞습니까? console.log(id);은 함수를 인쇄하므로 TypeError가 발생합니다. 그렇지 않다면, 어떻게해야합니까? 당신이 responseXML 속성에 의해 직접 xmlDoc을 얻을 수 있기 때문에
function xmlParser(xmlResponse) { 
    if (window.DOMParser) { 
     parser = new DOMParser(); 
     console.log(xmlResponse); 
     xmlDoc = parser.parseFromString(xmlResponse, "text/xml"); 
     console.log(xmlDoc); 
    } 
    id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue; 
    console.log(id); 
    key = xmlDoc.getElementsByTagName("passkey")[0].childNodes[0].nodeValue; 
    console.log(key); 
    return format(id, key); 
} 

답변

0

아니, 당신은 응답을 변환 할 필요가 없습니다.

예 :

xmlDoc = xmlResponse.responseXML; // you'll probably need to change it because I don't know what is value of xmlResponse in your case 
id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue; 
//and so on... 
+0

서버의 응답의 콘텐츠 유형은 "text/xml"일 필요가 또는 인 responseXML 속성이 null이됩니다. – Ben

+0

변환 코드가 삭제되었습니다. 서블릿에서 XML을 보내고 있습니다. 하지만 여전히'Uncaught TypeError : undefined'자식 노드 '를 읽을 수 없습니다. – John

+0

... 나쁜데 ... – John

관련 문제