XML 파일을 읽으려고하는 자바 스크립트 기능이 있습니다.xml childNotes 브라우저마다 다를 수 있습니다.
다음<?xml version="1.0" encoding="ISO-8859-1"?>
<Exam>
<Question QuestionID="Q001" CorrectAnswer="A">
<Description>Does a final member variable have to be initialized at the time it's declared?</Description>
<AnswerA>No</AnswerA>
<AnswerB>Yes</AnswerB>
<AnswerC></AnswerC>
<AnswerD></AnswerD>
</Question>
</Exam>
날의 출력 결과를 보여 주시기 바랍니다 XML 파일
function readXML()
{
alert("readXML");
if(xmlDoc.readyState == 4 || xmlDoc.readyState == 'complete')
{
for(var i=0; i < xmlDoc.getElementsByTagName("Question").length; i++)
{
var CurrentTuple = xmlDoc.getElementsByTagName("Question")[i];
var QuestionID = CurrentTuple.attributes.getNamedItem("QuestionID").value;
var CorrectAnswer = CurrentTuple.attributes.getNamedItem("CorrectAnswer").value;
alert(QuestionID +":"+ CorrectAnswer);
var OutputDisplayString = "";
for(var j=0; j< CurrentTuple.childNodes.length; j++)
{
//alert(CurrentTuple.childNodes[j].nodeName);
OutputDisplayString += CurrentTuple.childNodes[j].nodeName;
OutputDisplayString += "\n";
}
alert(OutputDisplayString);
}
}
}
... "경고 (OutputDisplayString를);" Firefox와 함께.
#text
Description
#text
AnswerA
#text
AnswerB
#text
AnswerC
#text
AnswerD
#text
날 내가 IE를 사용하여 얻을 결과를 비교합시다.
---------------------------
Message from webpage
---------------------------
Description
AnswerA
AnswerB
AnswerC
AnswerD
---------------------------
OK
---------------------------
그래서 내가 알고 싶은 것은 내가 파이어 폭스에서 결과로 얻을 하는 #text입니다 것입니다.
그러면이 값이 #text이되어 "CurrentTuple.childNodes.length"childNotes의 정확한 수를 계산할 수 없습니다.
Firefox의 결과가 #text 인 것을 알려주십시오.
그리고 어떻게 childNotes의 정확한 수를 얻을 수 있습니다.
여기에 덧붙여서 마이크로 소프트는 꽤 많이 손을 뻗었습니다. 표준은 꽤 공백이 응용 프로그램에보고되어야한다는 것을 분명히하고 있습니다. 마이크로 소프트를 제외한 모든 XML 파서는 그렇게하는 것 같습니다. 데이터 지향 XML을 사용하면 공백은 무의미 해 보일 수 있지만 문서를 처리 할 때는 중요하게됩니다. –