xml文件:test.xml

<?xml version="1.0"?>  
  
<note>  
<to>George</to>  
<from>John</from>  
<heading>Reminder</heading>  
<body>Don't forget the meeting!</body>  
<lastname>Simth</lastname>  
  
</note>  

html文件:

<html>  
  
<head>  
  
    <script type="text/javascript">  
      
        function parseXML(){  
              
            try{  
                  
                xmlDoc= new ActiveXObject("Microsoft.XMLDOM");  
            }catch(e){  
                  
                try{  
                      
                    xmlDoc= document.implementation.createDocument("","",null);  
                }catch(e){  
                      
                    alert(e.message);  
                    return;  
                }  
            }  
            xmlDoc.async = false;  
            xmlDoc.load("../xml/test.xml");  
              
            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>  
</head>  
<body onload="parseXML()">  
  
    <h1>W3School.com.cn Internal Note</h1>  
    <p><b>To:</b><span id="to"></span><br/>  
    <b>From:</b><span id="from"></span><br/>  
    <b>Message:</b><span id="message"></span>  
    <p>  
      
      
</body>  
  
</html>  

 

相关文章:

  • 2021-11-26
  • 2022-02-07
  • 2022-12-23
  • 2021-06-16
  • 2021-06-14
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-11-26
  • 2021-10-07
  • 2021-05-23
相关资源
相似解决方案