Dieser Artikel beschreibt die Methode, XML durch JS zu analysieren. Teilen Sie es für Ihre Referenz. Die spezifische Implementierungsmethode lautet wie folgt:
<script type = "javaScript"> var txt = "<Note>"; txt = txt+"<to> George </to>"; txt = txt+"<from> John </from>"; txt = txt+"<Heading> Erinnerung </hulding>"; txt = txt+"<body> Vergiss das Meeting nicht! </body>"; txt = txt+"</note>"; if (window.domParser) // Nicht-IE-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] .nodeDealue; document.getElementById ("from"). InnerHtml = xmldoc.getElementsByTagName ("from") [0] .Childnodes [0] .nodeValue; document.getElementById ("message"). innerhtml = xmldoc.getElementsByTagName ("Body") [0] .Childnodes [0] .nodeValue; </script>Ich hoffe, dieser Artikel wird für JavaScript -Programme aller hilfreich sein.