<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js 解析xml文件</title> </head> <body> <script type="text/javascript"> var xmlDoc=document.implementation.createDocument("","",null); xmlDoc.async=false; xmlDoc.load("one.xml"); //返回的是一个数组对象 var files = xmlDoc.getElementsByTagName('name'); //获取name标签中的文本 var arrs = []; for (var i = 0; i < files.length; i++) { arrs.push(files[i].innerHTML); }; console.log(arrs); </script> </body> </html>