이 기사에서는 JS에 의해 XML을 구문 분석하는 방법에 대해 설명합니다. 참조를 위해 공유하십시오. 특정 구현 방법은 다음과 같습니다.
<script type = "javaScript"> var txt = "<note>"; txt = txt+"<to> george </to>"; txt = txt+"<f> john </from>"; txt = txt+"<Heading> 알림 </heading>"; txt = txt+"<bod> 회의를 잊지 마세요! </body>"; txt = txt+"</note>"; if (window.domparser) // nonie 브라우저 {parser = new domparser (); xmldoc = parser.parsefromstring (txt, "text/xml"); } else // 즉, 브라우저 {xmldoc = new ActiveXobject ( "microsoft.xmldom"); xmldoc.async = "false"; xmldoc.loadxml (txt); } document.getElementById ( "to"). innerhtml = xmldoc.getElementsByTagName ( "to") [0] .ChildNodes [0] .nodevalue; document.getElementById ( "from"). innerHtml = xmldoc.getElementsByTagName ( "from") [0] .ChildNodes [0] .nodevalue; document.getElementById ( "message"). innerhtml = xmldoc.getElementsByTagName ( "body") [0] .ChildNodes [0] .nodevalue; </스크립트>이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.