この記事では、JSによるXMLを解析する方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
<script type = "javascript"> var txt = "<nte>"; txt = txt+"<to> george </to>"; txt = txt+"<from> john </from>"; txt = txt+"<heading> reminder </heading>"; txt = txt+"<body>会議を忘れないでください!</body>"; txt = txt+"</note>"; if(window.domparser)// nonie browser {parser = new domparser(); xmldoc = parser.parsefromstring(txt、 "text/xml"); } else // ie browser {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; </script>この記事がみんなのJavaScriptプログラミングに役立つことを願っています。